Examples of SimpleFeatureBuilder


Examples of org.geotools.feature.simple.SimpleFeatureBuilder

  @Test
  public void create() throws Exception {
    WKTReader wktReader = new WKTReader();
    Point geometry = (Point) wktReader.read("POINT (0 0)");

    SimpleFeatureBuilder build = new SimpleFeatureBuilder(layer.getSchema());
    SimpleFeature feature = build.buildFeature("100000", new Object[] { geometry, "Tsjakamaka", 342 });

    Object created = layer.create(feature);
    Assert.assertNotNull(created);
  }
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureBuilder

  private FeatureCollection<SimpleFeatureType, SimpleFeature> createCollection(List<InternalFeature> features,
      VectorLayer layer, CoordinateReferenceSystem mapCrs, Style style) {
    SimpleFeatureType type = createFeatureType(layer, mapCrs);
    ListFeatureCollection result = new ListFeatureCollection(type);
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    StyleAttributeExtractor extractor = new StyleAttributeExtractor();
    style.accept(extractor);
    Set<String> styleAttributeNames = extractor.getAttributeNameSet();
    FeatureInfo featureInfo = layer.getLayerInfo().getFeatureInfo();
    for (InternalFeature internalFeature : features) {
      // 2 more attributes : geometry + style attribute
      Object[] values = new Object[internalFeature.getAttributes().size() + 2];
      int i = 0;
      for (AttributeInfo attrInfo : featureInfo.getAttributes()) {
        String name = attrInfo.getName();
        if (styleAttributeNames.contains(name)) {
          values[i++] = internalFeature.getAttributes().get(name).getValue();
        } else {
          values[i++] = null;
        }
      }
      values[i++] = internalFeature.getStyleInfo().getIndex();
      values[i++] = internalFeature.getGeometry();
      result.add(builder.buildFeature(internalFeature.getId(), values));
    }
    return result;
  }
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureBuilder

    return toSimpleFeatureType(vectorLayerInfo, null);
  }

  /** {@inheritDoc} */
  public SimpleFeature toSimpleFeature(InternalFeature feature, SimpleFeatureType featureType) {
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
    List<Object> attr = new ArrayList<Object>();

    for (AttributeDescriptor ads : featureType.getAttributeDescriptors()) {
      if (!ads.equals(featureType.getGeometryDescriptor())) {
        Attribute a = feature.getAttributes().get(ads.getName().getLocalPart());
        if (null != a) {
          attr.add(a.getValue());
        } else {
          attr.add(null);
        }
      } else {
        attr.add(feature.getGeometry());
      }
    }

    return builder.buildFeature(feature.getId(), attr.toArray());

  }
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureBuilder

  public GeoToolsFeatureModel(DataStore dataStore, String featureSourceName, int srid,
      DtoConverterService converterService) throws LayerException {
    setDataStore(dataStore);
    setFeatureSourceName(featureSourceName);
    this.srid = srid;
    builder = new SimpleFeatureBuilder(getSchema());
    this.converterService = converterService;
  }
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureBuilder

                    "agency:String"    
            );
         
          SimpleFeatureCollection collection = FeatureCollections.newCollection();

            SimpleFeatureBuilder featureBuilder = null;
           
            if(gisExport.type.equals(GisUploadType.STOPS))
            {
              dataStore.createSchema(STOP_TYPE);
              featureBuilder = new SimpleFeatureBuilder(STOP_TYPE);
             
              List<Stop> stops = Stop.find("agency in (:ids)").bind("ids", gisExport.agencies).fetch();
             
              for(Stop s : stops)
              {
                featureBuilder.add(s.locationPoint());
                    featureBuilder.add(s.stopName);
                    featureBuilder.add(s.stopCode);
                    featureBuilder.add(s.stopDesc);
                    featureBuilder.add(s.gtfsStopId);
                    featureBuilder.add(s.agency.name);
                    SimpleFeature feature = featureBuilder.buildFeature(null);
                    collection.add(feature)
              }
            }
            else if(gisExport.type.equals(GisUploadType.ROUTES))
            {
              dataStore.createSchema(ROUTE_TYPE);
              featureBuilder = new SimpleFeatureBuilder(ROUTE_TYPE);
             
                List<Route> routes = Route.find("agency in (:ids)").bind("ids", gisExport.agencies).fetch();
             
                // check for duplicates

                // HashMap<String, Boolean> existingRoutes = new HashMap<String,Boolean>();
               
              for(Route r : routes)
              {
//                String routeId = r.routeLongName + "_" + r.routeDesc + "_ " + r.phone.id;
//               
//                if(existingRoutes.containsKey(routeId))
//                  continue;
//                else
//                  existingRoutes.put(routeId, true);
               
               
                List<TripPattern> patterns = TripPattern.find("route = ?", r).fetch();
                for(TripPattern tp : patterns)
                  {
                  if(tp.shape == null)
                    continue;
               
                  featureBuilder.add(tp.shape.shape);
                  featureBuilder.add(tp.name);
                  featureBuilder.add(r.routeShortName);
                      featureBuilder.add(r.routeLongName);
                      featureBuilder.add(r.routeDesc);
                     
                      if(r.routeType != null)
                        featureBuilder.add(r.routeType.toString());
                      else
                        featureBuilder.add("");
                     
                      featureBuilder.add(r.routeUrl);
                      featureBuilder.add(r.routeColor);
                      featureBuilder.add(r.routeTextColor);
                      featureBuilder.add(r.agency.name);
                      SimpleFeature feature = featureBuilder.buildFeature(null);
                      collection.add(feature)
                  }
              }
            }
            else
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureBuilder

                // and then create the features
                Coordinate c = new Coordinate(lon, lat);
                Point point = gF.createPoint(c);
                Geometry reprojectPoint = JTS.transform(point, transform);

                SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
                Object[] values = new Object[]{reprojectPoint, text, dateTimeString, String.valueOf(altim)};
                builder.addAll(values);
                SimpleFeature feature = builder.buildFeature(featureType.getTypeName() + "." + i++);
                newCollection.add(feature);
                pm.worked(1);
            }
        } finally {
            pm.done();
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureBuilder

                }
                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());
            DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
            int index = 0;
            for( GpsLog log : logsList ) {
                List<GpsPoint> gpsPointList = log.points;
                for( GpsPoint gpsPoint : gpsPointList ) {
                    Coordinate c = new Coordinate(gpsPoint.lon, gpsPoint.lat);
                    Point point = gF.createPoint(c);

                    Point reprojectPoint = (Point) JTS.transform(point, transform);
                    Object[] values = new Object[]{reprojectPoint, String.valueOf(gpsPoint.altim), gpsPoint.utctime};

                    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
                    builder.addAll(values);
                    SimpleFeature feature = builder.buildFeature(featureType.getTypeName() + "." + index++);
                    newCollection.add(feature);
                }
                pm.worked(1);
            }
            pm.done();
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureBuilder

                    Point reprojectPoint = (Point) JTS.transform(point, transform);
                    String dateTime = dateString + timeString;
                    Object[] values = new Object[]{reprojectPoint, String.valueOf(altim), dateTime, azimuth, imageRelativePath};

                    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
                    builder.addAll(values);
                    SimpleFeature feature = builder.buildFeature(null);
                    newCollection.add(feature);
                }
                pm.worked(1);
            }
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureBuilder

                                pm.beginTask("Converting geometries of places...", size);
                                int id = 0;
                                for( String name : keySet ) {
                                    Coordinate coordinate = placesMap.get(name);
                                    MultiPoint point = gF.createMultiPoint(new Coordinate[]{coordinate});
                                    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
                                    Object[] values = new Object[]{point, name};
                                    builder.addAll(values);
                                    SimpleFeature feature = builder.buildFeature(type.getTypeName() + "." + id);
                                    id++;
                                    newCollection.add(feature);
                                    pm.worked(1);
                                }
                                pm.done();
View Full Code Here

Examples of org.geotools.feature.simple.SimpleFeatureBuilder

                }
                if (line.startsWith("#")) {
                    continue;
                }

                SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
                Object[] values = new Object[fieldNames.size() - 1];

                String[] lineSplit = line.split(separator);
                double x = Double.parseDouble(lineSplit[xIndex]);
                double y = Double.parseDouble(lineSplit[yIndex]);
                Point point = gf.createPoint(new Coordinate(x, y));
                values[0] = point;

                int objIndex = 1;
                for( int i = 0; i < lineSplit.length; i++ ) {
                    if (i == xIndex || i == yIndex) {
                        continue;
                    }

                    String value = lineSplit[i];
                    int typeIndex = orderedTypeIndexesArray[i];
                    String typeName = typesArray[typeIndex];
                    if (typeName.equals(typesArray[3])) {
                        values[objIndex] = value;
                    } else if (typeName.equals(typesArray[4])) {
                        values[objIndex] = new Double(value);
                    } else if (typeName.equals(typesArray[5])) {
                        values[objIndex] = new Integer(value);
                    } else {
                        throw new IllegalArgumentException("An undefined value type was found");
                    }
                    objIndex++;
                }
                builder.addAll(values);

                SimpleFeature feature = builder.buildFeature(featureType.getTypeName() + "." + featureId);
                featureId++;
                newCollection.add(feature);
            }
        } finally {
            if (bR != null)
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.