Examples of SimpleFeatureTypeBuilder


Examples of org.geotools.feature.simple.SimpleFeatureTypeBuilder

    }
    return result;
  }

  private SimpleFeatureType createFeatureType(VectorLayer layer, CoordinateReferenceSystem mapCrs) {
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    VectorLayerInfo info = layer.getLayerInfo();
    builder.setName(info.getFeatureInfo().getDataSourceName());
    builder.setCRS(mapCrs);
    for (AttributeInfo attrInfo : info.getFeatureInfo().getAttributes()) {
      if (attrInfo instanceof PrimitiveAttributeInfo) {
        PrimitiveAttributeInfo prim = (PrimitiveAttributeInfo) attrInfo;
        switch (prim.getType()) {
          case BOOLEAN:
            builder.add(prim.getName(), Boolean.class);
            break;
          case CURRENCY:
            builder.add(prim.getName(), BigDecimal.class);
            break;
          case DATE:
            builder.add(prim.getName(), Date.class);
            break;
          case DOUBLE:
            builder.add(prim.getName(), Double.class);
            break;
          case FLOAT:
            builder.add(prim.getName(), Float.class);
            break;
          case INTEGER:
            builder.add(prim.getName(), Integer.class);
            break;
          case LONG:
            builder.add(prim.getName(), Long.class);
            break;
          case SHORT:
            builder.add(prim.getName(), Short.class);
            break;
          case STRING:
          case URL:
          case IMGURL:
            builder.add(prim.getName(), String.class);
            break;
          default:
            throw new IllegalStateException("Unknown primitive attribute type " + prim.getType());
        }
      } else if (attrInfo instanceof AssociationAttributeInfo) {
        AssociationAttributeInfo ass = (AssociationAttributeInfo) attrInfo;
        switch (ass.getType()) {
          case MANY_TO_ONE:
            builder.add(ass.getName(), Object.class);
            break;
          case ONE_TO_MANY:
            builder.add(ass.getName(), Collection.class);
            break;
          default:
            throw new IllegalStateException("Unknown association attribute type " + ass.getType());
        }
      }
    }
    // add the extra style index attribute
    builder.add(STYLE_INDEX_ATTRIBUTE_NAME, Integer.class);
    // add the geometry attribute
    GeometryAttributeInfo geom = info.getFeatureInfo().getGeometryType();
    builder.add(geom.getName(), dtoConverterService.toInternal(info.getLayerType()), mapCrs);
    builder.setDefaultGeometry(geom.getName());
    return builder.buildFeatureType();
  }
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureTypeBuilder

  /** {@inheritDoc} */
  public SimpleFeatureType toSimpleFeatureType(VectorLayerInfo vectorLayerInfo, List<String> attributeNames)
      throws LayerException {

    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();

    builder.setName(vectorLayerInfo.getFeatureInfo().getDataSourceName());
    builder.setNamespaceURI(NAMESPACE_URI);
    builder.setCRS(geoservice.getCrs2(vectorLayerInfo.getCrs()));

    // create a lookup map of attribute info's
    Map<String, AttributeInfo> attrs = new LinkedHashMap<String, AttributeInfo>();
    for (AttributeInfo a : vectorLayerInfo.getFeatureInfo().getAttributes()) {
      attrs.put(a.getName(), a);
    }
    if (attributeNames == null) {
      attributeNames = new ArrayList<String>(attrs.keySet());
    }

    // now list 'm up
    for (String name : attributeNames) {
      if (attrs.containsKey(name)) {
        AttributeInfo a = attrs.get(name);
        if (a instanceof PrimitiveAttributeInfo) {
          PrimitiveAttributeInfo attr = (PrimitiveAttributeInfo) a;
          switch (attr.getType()) {
            case BOOLEAN:
              builder.add(attr.getName(), Boolean.class);
              break;
            case SHORT:
              builder.add(attr.getName(), Short.class);
              break;
            case INTEGER:
              builder.add(attr.getName(), Integer.class);
              break;
            case LONG:
              builder.add(attr.getName(), Long.class);
              break;
            case FLOAT:
              builder.add(attr.getName(), Float.class);
              break;
            case DOUBLE:
              builder.add(attr.getName(), Double.class);
              break;
            case CURRENCY:
            case STRING:
            case URL:
            case IMGURL:
              builder.add(attr.getName(), String.class);
              break;
            case DATE:
              builder.add(attr.getName(), Date.class);
              break;
            default:
              log.error("Don't know how to convert attribute of type " + attr.getType() + ", skipped, " +
                  attr);
              break;
          }
        }
      }
    }
    builder.add(vectorLayerInfo.getFeatureInfo().getGeometryType().getName(), Geometry.class);
    builder.setDefaultGeometry(vectorLayerInfo.getFeatureInfo().getGeometryType().getName());

    return builder.buildFeatureType();
  }
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureTypeBuilder

    }

    private void notesToShapefile( Connection connection, File outputFolderFile, IProgressMonitor pm ) throws Exception {
        File outputShapeFile = new File(outputFolderFile, GEOPAPARAZZI_NOTES_OUTPUTSHAPEFILENAME);

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("geopaparazzinotes"); //$NON-NLS-1$
        b.setCRS(mapCrs);
        b.add("the_geom", Point.class); //$NON-NLS-1$
        for( String fieldName : GEOPAPARAZZI_NOTES_DESCRIPTIONFIELDS ) {
            b.add(fieldName, String.class);
        }
        SimpleFeatureType featureType = b.buildFeatureType();
        MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, mapCrs);
        pm.beginTask("Import notes...", IProgressMonitor.UNKNOWN);
        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();

        Statement statement = null;
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureTypeBuilder

        }

        /*
         * create the lines shapefile
         */
        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("geopaparazzinotes");
        b.setCRS(mapCrs);
        b.add("the_geom", MultiLineString.class);
        b.add("STARTDATE", String.class);
        b.add("ENDDATE", String.class);
        b.add("DESCR", String.class);
        SimpleFeatureType featureType = b.buildFeatureType();

        try {
            MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, mapCrs);
            pm.beginTask("Import gps to lines...", logsList.size());
            DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
            int index = 0;
            for( GpsLog log : logsList ) {
                List<GpsPoint> points = log.points;

                List<Coordinate> coordList = new ArrayList<Coordinate>();
                String startDate = log.startTime;
                String endDate = log.endTime;
                for( GpsPoint gpsPoint : points ) {
                    Coordinate c = new Coordinate(gpsPoint.lon, gpsPoint.lat);
                    coordList.add(c);
                }
                Coordinate[] coordArray = (Coordinate[]) coordList.toArray(new Coordinate[coordList.size()]);
                if (coordArray.length < 2) {
                    continue;
                }
                LineString lineString = gF.createLineString(coordArray);
                LineString reprojectLineString = (LineString) JTS.transform(lineString, transform);
                MultiLineString multiLineString = gF.createMultiLineString(new LineString[]{reprojectLineString});

                SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
                Object[] values = new Object[]{multiLineString, startDate, endDate, log.text};
                builder.addAll(values);
                SimpleFeature feature = builder.buildFeature(featureType.getTypeName() + "." + index++);

                newCollection.add(feature);
                pm.worked(1);
            }
            pm.done();

            ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
            Map<String, Serializable> params = new HashMap<String, Serializable>();
            params.put("url", outputLinesShapeFile.toURI().toURL());
            params.put("create spatial index", Boolean.TRUE);
            ShapefileDataStore dStore = (ShapefileDataStore) factory.createNewDataStore(params);
            dStore.createSchema(featureType);
            dStore.forceSchemaCRS(mapCrs);

            JGrassToolsPlugin.getDefault().writeToShapefile(dStore, newCollection);

            JGrassToolsPlugin.getDefault().addServiceToCatalogAndMap(outputLinesShapeFile.getAbsolutePath(), true, true,
                    new NullProgressMonitor());

        } catch (Exception e1) {
            JGrassToolsPlugin.log(e1.getLocalizedMessage(), e1);
            e1.printStackTrace();
        }
        /*
         * create the points shapefile
         */

        File outputPointsShapeFile = new File(outputFolderFile, "gpspoints.shp");

        b = new SimpleFeatureTypeBuilder();
        b.setName("geopaparazzinotes");
        b.setCRS(mapCrs);
        b.add("the_geom", Point.class);
        b.add("ALTIMETRY", String.class);
        b.add("DATE", String.class);
        featureType = b.buildFeatureType();

        try {
            MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, mapCrs);

            pm.beginTask("Import gps to points...", logsList.size());
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureTypeBuilder

             * create the points shapefile
             */

            File outputPointsShapeFile = new File(outputFolderFile, "mediapoints.shp");

            SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
            b.setName("geopaparazzinotes");
            b.setCRS(mapCrs);
            b.add("the_geom", Point.class);
            b.add("ALTIMETRY", String.class);
            b.add("DATE", String.class);
            b.add("AZIMUTH", Double.class);
            b.add("IMAGE", String.class);
            SimpleFeatureType featureType = b.buildFeatureType();

            MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, mapCrs);

            DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
            for( File imageFile : listFiles ) {
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureTypeBuilder

    public void setPassword(String pwd){
        password = pwd;
    }
   
    static private SimpleFeatureType createAddressType( List<String> keys ) {
      SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
      builder.setName("Address");
        for( String key : keys ){
            if( "long".equals(key) || "lat".equals(key)) continue;             //$NON-NLS-1$ //$NON-NLS-2$
            builder.add(key, String.class);
        }
        String geometryAtt = "location";
    builder.add(geometryAtt, Point.class, DefaultGeographicCRS.WGS84); //$NON-NLS-1$
        builder.setDefaultGeometry(geometryAtt);
       
        try {
            return builder.buildFeatureType(); //$NON-NLS-1$
        } catch (Throwable e) {
            return null;
        }
    }
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureTypeBuilder

       
        //2. hole
        Polygon hole = (Polygon) reader.read("POLYGON ((112 112, 118 112, 118 118, 112 118, 112 112))");
       
        //add the two geometries to a FeatureCollection
        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName( "Test" );
        b.add( "location", Polygon.class );
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeature donutFeature = SimpleFeatureBuilder.build(type, new Object[]{donut}, "fid.1");
        SimpleFeature holeFeature = SimpleFeatureBuilder.build(type, new Object[]{hole}, "fid.2");
        DefaultFeatureCollection fc = new DefaultFeatureCollection();
        fc.add(donutFeature);
        fc.add(holeFeature);
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureTypeBuilder

                        public void run( IProgressMonitor pm ) throws InvocationTargetException, InterruptedException {

                            try {
                                GeometryFactory gF = new GeometryFactory();
                                // create the feature type
                                SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
                                b.setName("places");
                                b.setCRS(DefaultGeographicCRS.WGS84);
                                b.add("the_geom", MultiPoint.class);
                                b.add("name", String.class);
                                SimpleFeatureType type = b.buildFeatureType();

                                DefaultFeatureCollection newCollection = new DefaultFeatureCollection();

                                int size = keySet.size();
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureTypeBuilder

        if (separator == null) {
            separator = ",";
        }

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("csvimport");
        b.setCRS(crs);
        b.add("the_geom", Point.class);

        int xIndex = -1;
        int yIndex = -1;
        Set<String> fieldNames = fieldsAndTypesIndex.keySet();
        String[] fieldNamesArray = (String[]) fieldNames.toArray(new String[fieldNames.size()]);
        for( int i = 0; i < fieldNamesArray.length; i++ ) {
            String fieldName = fieldNamesArray[i];
            Integer typeIndex = fieldsAndTypesIndex.get(fieldName);

            if (typeIndex == 0) {
                xIndex = i;
            } else if (typeIndex == 1) {
                yIndex = i;
            } else {
                Class<?> class1 = typesMap.get(typesArray[typeIndex]);
                b.add(fieldName, class1);
            }
        }
        SimpleFeatureType featureType = b.buildFeatureType();

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        Collection<Integer> orderedTypeIndexes = fieldsAndTypesIndex.values();
        Integer[] orderedTypeIndexesArray = (Integer[]) orderedTypeIndexes.toArray(new Integer[orderedTypeIndexes.size()]);
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureTypeBuilder

     * You cannot call this once the dialog is closed, see the okPressed method.
     * @return a SimpleFeatureType created based on the contents of Text
     */
    private SimpleFeatureType createFeatureType() throws SchemaException {

        SimpleFeatureTypeBuilder build = new SimpleFeatureTypeBuilder();
       
        transform = createTransformProcessDefinitionList();
       
        for( Definition definition : transform ){
            String name = definition.name;
            Expression expression = definition.expression;

            // FIXME : sometimes expression returns null.  I think the real bug is with AttributeExpression
            Class<?> binding = definition.binding;
            if( binding == null ){
                Object value = expression.evaluate(sample);
                if( value == null){
                    ifexpression instanceof PropertyName){
                        String path = ((PropertyName)expression).getPropertyName();
                        AttributeType attributeType = sample.getFeatureType().getType(path);
                        if( attributeType == null ){
                            String msg = Messages.ReshapeOperation_4;
                            throw new ReshapeException(format(msg, name, path));
                        }
                        binding = attributeType.getClass();
                    }
                } else {
                    binding = value.getClass();
                }
                if( binding ==null ){
                    String msg = Messages.ReshapeOperation_5;
                    throw new ReshapeException(format(msg, name));
                }
            }
            if( Geometry.class.isAssignableFrom( binding )){
                CoordinateReferenceSystem crs;
                AttributeType originalAttributeType = originalFeatureType.getType(name);
                if( originalAttributeType == null && originalAttributeType instanceof GeometryType ) {
                    crs = ((GeometryType)originalAttributeType).getCoordinateReferenceSystem();
                } else {
                    crs = originalFeatureType.getCoordinateReferenceSystem();
                }
                build.crs(crs);
                build.add(name, binding);
            }
            else {
                build.add(name, binding);
            }
        }
        build.setName( ReshapeOperation.getNewTypeName( originalFeatureType.getTypeName() ) );
       
        return build.buildFeatureType();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.