view geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEUtils.java @ 879:9bcc423d8d76

Added Support for SpatialQueries using LineString as Geometry of Interest. geo-backend/trunk@790 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 16 Mar 2010 14:07:18 +0000
parents 0b813ae17173
children 12f88239fb33
line wrap: on
line source
/**
 * Title:           ArcSDEUtils, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/sde/ArcSDEUtils.java,v 1.7 2007/11/28 14:05:39 blume Exp $
 * Source:          $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/sde/ArcSDEUtils.java,v $
 * created by:      Stefan Blume (blume)
 * erstellt am:     21.11.2007
 * Copyright:       con terra GmbH, 2005
 *
 * modified by:     $Author: blume $
 * modified on:     $Date: 2007/11/28 14:05:39 $
 * Version:         $Revision: 1.7 $
 * TAG:             $Name:  $
 * locked from:     $Locker:  $
 * CVS State:       $State: Exp $
 * Project:         $ProjectName$
 */
package de.intevation.gnv.geobackend.sde.datasources;

import java.util.Vector;

import org.apache.log4j.Logger;

import com.esri.sde.sdk.client.SDEPoint;
import com.esri.sde.sdk.client.SeColumnDefinition;
import com.esri.sde.sdk.client.SeError;
import com.esri.sde.sdk.client.SeException;
import com.esri.sde.sdk.client.SeTable;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;

/**
 * The class <code>ArcSDEUtils</code> fulfills the following purposes:
 * <ol>
 * <li></li>
 * </ol>
 * 
 * @author blume
 * @version 1.0
 * @serial 1.0
 * @see
 * @since 21.11.2007 08:20:40
 */
public class ArcSDEUtils {

    /**
     * Default Logging instance
     */
    private static Logger sLogger = Logger.getLogger(ArcSDEUtils.class);

    public void displayStats(SeTable.SeTableStats tableStats) {

        sLogger.debug("\n--> Table Statistics\n");
        if (tableStats != null) {

            sLogger.debug("Average - " + tableStats.getAverage());
            sLogger.debug("No of rows - " + tableStats.getCount());
            sLogger.debug("Maximum Value - " + tableStats.getMax());
            sLogger.debug("Minimum Value - " + tableStats.getMin());
            sLogger.debug("No of distinct values - "
                          + tableStats.getNumDistinct());
            sLogger.debug("Standard Deviation - " + tableStats.getStdDev());

            sLogger.debug("Distinct type - "
                          + ArcSDEUtils.resolveType(tableStats
                                  .getDistinctType()));

            int[] distinctFreq = tableStats.getDistinctValueFrequencies();
            Vector distinctValues = tableStats.getDistinctValues();
            sLogger.debug("Distinct values & their frequencies : ");
            for (int i = 0; i < distinctFreq.length; i++)
                sLogger.debug(distinctValues.elementAt(i) + " - "
                              + distinctFreq[i]);
        }// End if

    }// End displayStats

    /**
     * Takes an integer corresponding to an ArcSDE data type and returns a
     * string description of the type.
     * 
     * @param type
     *            SDE data type bit-mask.
     */
    public static String resolveType(int type) {

        String typeName = "Invalid Type";
        switch (type) {

        case SeColumnDefinition.TYPE_SMALLINT:
            typeName = "Small Int";
            break;
        case SeColumnDefinition.TYPE_INTEGER:
            typeName = "Int";
            break;
        case SeColumnDefinition.TYPE_FLOAT:
            typeName = "Float";
            break;
        case SeColumnDefinition.TYPE_DOUBLE:
            typeName = "Double";
            break;
        case SeColumnDefinition.TYPE_STRING:
            typeName = "String";
            break;
        case SeColumnDefinition.TYPE_BLOB:
            typeName = "Blob";
            break;
        case SeColumnDefinition.TYPE_DATE:
            typeName = "Date";
            break;
        case SeColumnDefinition.TYPE_SHAPE:
            typeName = "Shape";
            break;
        case SeColumnDefinition.TYPE_RASTER:
            typeName = "Raster";
            break;
        }
        return typeName;
    }// End method resolveType

    public static void printError(SeException exception) {

        SeError error = exception.getSeError();

        sLogger.debug("\n ArcSDE Error Number        : " + error.getSdeError());
        sLogger.debug(" Error Description          : " + error.getErrDesc());

        int extError = error.getExtError();
        if (extError != 0)
            sLogger.debug(" Extended Error Number      : " + extError);

        String desc = error.getSdeErrMsg();
        if (desc != null && desc.length() != 0)
            sLogger.debug(" Extended Error Description : " + desc);

        desc = error.getExtErrMsg();
        if (desc != null && desc.length() != 0)
            sLogger.debug(" Extended Error Description : " + desc);

        sLogger.debug(exception);

    }// End printError

    public SDEPoint[] createPoints(Geometry g) {
        sLogger.debug("createPoints()");
        Coordinate[] coords = null;
        if (g instanceof Polygon) {
            coords = ((Polygon) g).getCoordinates();
        }else if (g instanceof Point){
            coords = ((Point)g).getCoordinates();
        }else if (g instanceof LineString){
            coords = ((LineString)g).getCoordinates();
        }else{
            coords = g.getCoordinates();
        }
        
        if (coords != null){
            SDEPoint[] lSDEPoints = new SDEPoint[coords.length];
            for (int i = 0; i < coords.length; i++) {
                lSDEPoints[i] = new SDEPoint(coords[i].x, coords[i].y);
            }
            return lSDEPoints;
        }else{
            return null;
        }

    }
}

http://dive4elements.wald.intevation.org