Java Code Examples for org.geotools.feature.simple.SimpleFeatureTypeBuilder#buildFeatureType()
The following examples show how to use
org.geotools.feature.simple.SimpleFeatureTypeBuilder#buildFeatureType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OmsLW04_BankfullWidthAnalyzer.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private DefaultFeatureCollection getWidthLines( CoordinateReferenceSystem crs, ConcurrentLinkedQueue<Object[]> validPointsLineList ) throws Exception { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("net"); b.setCRS(crs); b.add("the_geom", LineString.class); b.add(PFAF, String.class); b.add(LINKID, Integer.class); b.add(ARiverSectionsExtractor.FIELD_SECTION_ID, Integer.class); b.add(ARiverSectionsExtractor.FIELD_PROGRESSIVE, Double.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); for( Object[] objects : validPointsLineList ) { builder.addAll(objects); SimpleFeature feature = builder.buildFeature(null); newCollection.add(feature); } return newCollection; }
Example 2
Source File: CentroidManagerGeoWave.java From geowave with Apache License 2.0 | 6 votes |
private static SimpleFeatureType createFeatureType( final SimpleFeatureType featureType, final Class<? extends Geometry> shapeClass) { try { final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(featureType.getName().getLocalPart()); builder.setNamespaceURI(featureType.getName().getNamespaceURI()); builder.setCRS(featureType.getCoordinateReferenceSystem()); for (final AttributeDescriptor attr : featureType.getAttributeDescriptors()) { if (attr.getType() instanceof GeometryType) { builder.add(attr.getLocalName(), shapeClass); } else { builder.add(attr.getLocalName(), attr.getType().getBinding()); } } return builder.buildFeatureType(); } catch (final Exception e) { LOGGER.warn("Schema Creation Error. Hint: Check the SRID.", e); } return null; }
Example 3
Source File: TestLineSmootherMcMaster.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testVectorReader() throws Exception { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("test"); b.setCRS(DefaultGeographicCRS.WGS84); b.add("the_geom", LineString.class); b.add("id", Integer.class); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); SimpleFeatureType type = b.buildFeatureType(); Geometry line = new WKTReader().read("LINESTRING (0 0, 1 1, 2 2, 3 3, 4 4, 5 3, 6 2, 7 1, 8 0)"); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Object[] values = new Object[]{line, 0}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0"); newCollection.add(feature); OmsLineSmootherMcMaster smoother = new OmsLineSmootherMcMaster(); smoother.inVector = newCollection; smoother.pLookahead = 3; smoother.pSlide = 0.9; smoother.pDensify = 0.9; smoother.process(); SimpleFeatureCollection outFeatures = smoother.outVector; List<Geometry> geomList = FeatureUtilities.featureCollectionToGeometriesList(outFeatures, false, null); Geometry geometry = geomList.get(0); int newLength = geometry.getCoordinates().length; Geometry densifiedline = new WKTReader() .read("LINESTRING (0 0, 0.5 0.5, 1 1, 1.5 1.5, 2 2, 2.5 2.5, 3 3, 3.5 3.5, 4 4, 4.5 3.5, 5 3, 5.5 2.5, 6 2, 6.5 1.5, 7 1, 7.5 0.5, 8 0)"); int expectedLength = densifiedline.getCoordinates().length; assertEquals(expectedLength, newLength); }
Example 4
Source File: KMeansParallelInitializeTest.java From geowave with Apache License 2.0 | 5 votes |
private SimpleFeatureBuilder getBuilder() { final SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName("test"); typeBuilder.setCRS(DefaultGeographicCRS.WGS84); // <- Coordinate // reference // add attributes in order typeBuilder.add("geom", Geometry.class); typeBuilder.add("name", String.class); typeBuilder.add("count", Long.class); // build the type return new SimpleFeatureBuilder(typeBuilder.buildFeatureType()); }
Example 5
Source File: TestLineSmootherJaitools.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testVectorReader() throws Exception { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("test"); b.setCRS(DefaultGeographicCRS.WGS84); b.add("the_geom", LineString.class); b.add("id", Integer.class); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); SimpleFeatureType type = b.buildFeatureType(); Geometry line = new WKTReader().read("LINESTRING (0 0, 1 1, 2 0)");//2 2, 3 3, 4 4, 5 3, 6 2, 7 1, 8 0)"); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Object[] values = new Object[]{line, 0}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0"); newCollection.add(feature); OmsLineSmootherJaitools smoother = new OmsLineSmootherJaitools(); smoother.inVector = newCollection; smoother.pAlpha = 1; smoother.process(); SimpleFeatureCollection outFeatures = smoother.outVector; List<Geometry> geomList = FeatureUtilities.featureCollectionToGeometriesList(outFeatures, false, null); Geometry geometry = geomList.get(0); int newLength = geometry.getCoordinates().length; Geometry densifiedline = new WKTReader() .read("LINESTRING (0 0, 0.0342935528120713 0.0342935528120713, 0.1262002743484225 0.1262002743484225, 0.2592592592592592 0.2592592592592592, 0.4170096021947873 0.4170096021947873, 0.5829903978052127 0.5829903978052127, 0.7407407407407407 0.7407407407407407, 0.8737997256515775 0.8737997256515775, 0.9657064471879286 0.9657064471879286, 1 1, 1.0342935528120714 0.9657064471879288, 1.1262002743484225 0.8737997256515775, 1.2592592592592593 0.7407407407407408, 1.4170096021947873 0.5829903978052127, 1.5829903978052127 0.4170096021947874, 1.7407407407407407 0.2592592592592593, 1.8737997256515775 0.1262002743484225, 1.9657064471879289 0.0342935528120714, 2 0)"); int expectedLength = densifiedline.getCoordinates().length; assertEquals(expectedLength, newLength); }
Example 6
Source File: DateFieldRetypingSource.java From geowave with Apache License 2.0 | 5 votes |
@Override public SimpleFeatureType getRetypedSimpleFeatureType() { debugType("IN", typeIn); final SimpleFeatureTypeBuilder typeOutBuilder = new SimpleFeatureTypeBuilder(); // Manually set the basics and replace the date fields typeOutBuilder.setCRS(typeIn.getCoordinateReferenceSystem()); typeOutBuilder.setDescription(typeIn.getDescription()); typeOutBuilder.setName(typeIn.getName()); for (final AttributeDescriptor att : typeIn.getAttributeDescriptors()) { if (fieldNameToTimestampFormat.containsKey(att.getLocalName())) { typeOutBuilder.add(att.getLocalName(), Date.class); } else { typeOutBuilder.add(att); } } // TODO - restore this procedure when support for GeoTools 12.x is // dropped // typeOutBuilder.init(typeIn); // for (Entry<String, String> fieldToChange : // fieldNameToTimestampFormat.entrySet()) { // final AttributeTypeBuilder dateFieldBuilder = new // AttributeTypeBuilder(); // dateFieldBuilder.setName(fieldToChange.getKey()); // dateFieldBuilder.setBinding(Date.class); // typeOutBuilder.set( // fieldToChange.getKey(), // dateFieldBuilder); // } final SimpleFeatureType typeOut = typeOutBuilder.buildFeatureType(); debugType("OUT", typeOut); return typeOut; }
Example 7
Source File: OmsTrentoPProjectFilesGenerator.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Build the Project Type. * * @param crs * @return the type for the calibration shp. */ private SimpleFeatureType getProjectFeatureType( CoordinateReferenceSystem crs ) { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); ITrentoPType[] values = TrentoPFeatureType.PipesTrentoP.values(); String typeName = values[0].getName(); b.setName(typeName); b.setCRS(crs); b.add("the_geom", LineString.class); // create ID attribute. b.add(values[0].getAttributeName(), values[0].getClazz()); // create drain area attribute. b.add(values[2].getAttributeName(), values[2].getClazz()); // create the percentage area. b.add(values[11].getAttributeName(), values[12].getClazz()); // The upstream elevation of the land. b.add(values[3].getAttributeName(), values[3].getClazz()); // The downstream elevation of the land. b.add(values[4].getAttributeName(), values[4].getClazz()); // runoff coefficent. b.add(values[5].getAttributeName(), values[5].getClazz()); // average residence time. b.add(values[6].getAttributeName(), values[6].getClazz()); // ks b.add(values[7].getAttributeName(), values[7].getClazz()); // minimum slope. b.add(values[8].getAttributeName(), values[8].getClazz()); // section type b.add(values[9].getAttributeName(), values[9].getClazz()); // average slope of the basin. b.add(values[10].getAttributeName(), values[10].getClazz()); return b.buildFeatureType(); }
Example 8
Source File: CorrelativeFieldSelectorTest.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private SimpleFeatureType createFeatureType(Class binding) { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("featureType"); builder.add("chl", Float.class); builder.add("sst", Double.class); builder.add("time", ProductData.UTC.class); builder.add("point", binding); builder.setDefaultGeometry("point"); return builder.buildFeatureType(); }
Example 9
Source File: TestVectorTableJoiner.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testVectorTableJoiner() throws Exception { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("test"); b.setCRS(DefaultGeographicCRS.WGS84); b.add("the_geom", Point.class); b.add("id", Integer.class); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Point point = GeometryUtilities.gf().createPoint(new Coordinate(0, 0)); Object[] values = new Object[]{point, 1}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0"); newCollection.add(feature); HashMap<String, List<Object>> tabledata = new HashMap<String, List<Object>>(); List<Object> id = Arrays.asList(new Object[]{1}); tabledata.put("id", id); List<Object> area = Arrays.asList(new Object[]{123.45}); tabledata.put("area", area); List<Object> area2 = Arrays.asList(new Object[]{67.89}); tabledata.put("area2", area2); OmsVectorTableJoiner joiner = new OmsVectorTableJoiner(); joiner.inVector = newCollection; joiner.tabledata = tabledata; joiner.fCommon = "id"; joiner.pFields = "area"; joiner.process(); SimpleFeatureCollection outFeatures = joiner.outVector; SimpleFeature f = FeatureUtilities.featureCollectionToList(outFeatures).get(0); String areaStr = f.getAttribute("area").toString(); assertTrue(areaStr.equals("123.45")); }
Example 10
Source File: OmsDebrisVandre.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private SimpleFeatureType createTriggersType() { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("indexedtriggers"); b.setCRS(inFlow.getCoordinateReferenceSystem()); b.add("the_geom", Point.class); b.add("PATHID", Integer.class); SimpleFeatureType type = b.buildFeatureType(); return type; }
Example 11
Source File: ShapefileTool.java From geowave with Apache License 2.0 | 5 votes |
private static SimpleFeatureType createFeatureType(final String typeName, final boolean isPoint) { final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(typeName); builder.setCRS(DefaultGeographicCRS.WGS84); // <- Coordinate reference // system // add attributes in order builder.add("the_geom", isPoint ? Point.class : Polygon.class); builder.length(15).add("Name", String.class); // <- 15 chars width for name field // build the type return builder.buildFeatureType(); }
Example 12
Source File: OmsHoughCirclesRaster.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inRaster, pMinRadius, pMaxRadius, pRadiusIncrement); if (pColorNv != null) { colorNv = pColorNv; useColorNv = true; } RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster); offx = 0; offy = 0; width = regionMap.getCols(); height = regionMap.getRows(); offset = width; xRes = regionMap.getXres(); radiusMinPixel = (int) round(width * pMinRadius / (regionMap.getEast() - regionMap.getWest())); radiusMaxPixel = (int) round(width * pMaxRadius / (regionMap.getEast() - regionMap.getWest()));; radiusIncPixel = (int) round(width * pRadiusIncrement / (regionMap.getEast() - regionMap.getWest())); if (radiusIncPixel < 1) { radiusIncPixel = 1; } maxCircles = pMaxCircleCount; depth = ((radiusMaxPixel - radiusMinPixel) / radiusIncPixel) + 1; Geometry[] circles = getCircles(); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("houghcircles"); b.setCRS(inRaster.getCoordinateReferenceSystem()); b.add("the_geom", Polygon.class); b.add("value", Double.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); DefaultFeatureCollection outFC = new DefaultFeatureCollection(); for( Geometry geometry : circles ) { Object[] values = new Object[]{geometry, referenceImageValue}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(null); outFC.add(feature); } outCircles = outFC; }
Example 13
Source File: OmsGeopaparazzi4Converter.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
private static BuilderAndCollectionPair getBuilderAndCollectionPair( IHMProgressMonitor pm, HashMap<String, BuilderAndCollectionPair> forms2PropertiesMap, String sectionName, Set<Entry<String, String>> entrySet, LinkedHashMap<String, String> typesMap, TreeMap<String, Integer> namesMap, String uniqueSectionName ) { BuilderAndCollectionPair builderAndCollectionPair = forms2PropertiesMap.get(uniqueSectionName); if (builderAndCollectionPair == null) { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName(sectionName); // $NON-NLS-1$ b.setCRS(DefaultGeographicCRS.WGS84); b.add("the_geom", Point.class); //$NON-NLS-1$ b.add(tsFN, String.class); // $NON-NLS-1$ b.add(altimFN, Double.class); // $NON-NLS-1$ b.add(dirtyFN, Integer.class); // $NON-NLS-1$ for( Entry<String, String> entry : entrySet ) { String key = entry.getKey(); String typeStr = typesMap.get(key); key = key.replaceAll("\\s+", "_"); if (key.length() > 10) { pm.errorMessage("Need to trim key: " + key); key = key.substring(0, 10); } Integer nCount = namesMap.get(key); if (nCount == null) { nCount = 1; namesMap.put(key, 1); } else { nCount++; namesMap.put(key, nCount); if (nCount < 10) { key = key.substring(0, key.length() - 1) + nCount; } else { key = key.substring(0, key.length() - 2) + nCount; } } Class< ? > clazz = String.class; if (Utilities.isStringType(typeStr)) { clazz = String.class; // redundant just to show that one can check } else if (Utilities.isIntegerType(typeStr)) { clazz = Integer.class; } else if (Utilities.isDoubleType(typeStr)) { clazz = Double.class; } b.add(key, clazz); } SimpleFeatureType featureType = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); builderAndCollectionPair = new BuilderAndCollectionPair(); builderAndCollectionPair.builder = builder; builderAndCollectionPair.collection = newCollection; forms2PropertiesMap.put(uniqueSectionName, builderAndCollectionPair); } return builderAndCollectionPair; }
Example 14
Source File: InternalFeatureCollection.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
private SimpleFeatureType createFeatureType(VectorLayer layer, CoordinateReferenceSystem mapCrs) { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); VectorLayerInfo info = layer.getLayerInfo(); builder.setName(info.getFeatureInfo().getDataSourceName()); builder.setCRS(mapCrs); for (AbstractAttributeInfo 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 SyntheticAttributeInfo) { SyntheticAttributeInfo synth = (SyntheticAttributeInfo) attrInfo; // can't determine type, using object builder.add(synth.getName(), Object.class); } } // add the geometry attribute GeometryAttributeInfo geom = info.getFeatureInfo().getGeometryType(); builder.add(geom.getName(), getGeometryBinding(info.getLayerType()), mapCrs); builder.setDefaultGeometry(geom.getName()); return builder.buildFeatureType(); }
Example 15
Source File: OmsGeopaparazzi3Converter.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
private void simpleNotesToShapefile( Connection connection, File outputFolderFile, IHMProgressMonitor pm ) throws Exception { File outputShapeFile = new File(outputFolderFile, "simplenotes.shp"); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("gpsimplenotes"); //$NON-NLS-1$ b.setCRS(crs); b.add("the_geom", Point.class); //$NON-NLS-1$ b.add("DESCR", String.class); b.add("TIMESTAMP", String.class); b.add("ALTIM", Double.class); SimpleFeatureType featureType = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType); pm.beginTask("Import simple notes...", -1); SimpleFeatureCollection newCollection = new DefaultFeatureCollection(); try (Statement statement = connection.createStatement()) { statement.setQueryTimeout(30); // set timeout to 30 sec. ResultSet rs = statement.executeQuery("select lat, lon, altim, ts, text, form from notes"); while( rs.next() ) { String form = rs.getString("form"); if (form != null && form.trim().length() != 0) { continue; } double lat = rs.getDouble("lat"); double lon = rs.getDouble("lon"); double altim = rs.getDouble("altim"); String dateTimeString = rs.getString("ts"); String text = rs.getString("text"); if (lat == 0 || lon == 0) { continue; } // and then create the features Coordinate c = new Coordinate(lon, lat); Point point = gf.createPoint(c); Object[] values = new Object[]{point, text, dateTimeString, altim}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(null); ((DefaultFeatureCollection) newCollection).add(feature); } } finally { pm.done(); } dumpVector(newCollection, outputShapeFile.getAbsolutePath()); }
Example 16
Source File: ElasticFilterTest.java From elasticgeo with GNU General Public License v3.0 | 4 votes |
@Before public void setUp() { ff = CommonFactoryFinder.getFilterFactory2(); SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName("test"); typeBuilder.add("stringAttr", String.class); typeBuilder.add("integerAttr", Integer.class); typeBuilder.add("longAttr", Long.class); typeBuilder.add("booleanAttr", Boolean.class); typeBuilder.add("doubleAttr", Double.class); typeBuilder.add("floatAttr", Float.class); typeBuilder.add("dateAttr", Date.class); AttributeDescriptor geoPointAtt; AttributeTypeBuilder geoPointAttBuilder = new AttributeTypeBuilder(); geoPointAttBuilder.setName("geo_point"); geoPointAttBuilder.setBinding(Point.class); geoPointAtt = geoPointAttBuilder.buildDescriptor("geo_point", geoPointAttBuilder.buildType()); geoPointAtt.getUserData().put(GEOMETRY_TYPE, ElasticGeometryType.GEO_POINT); typeBuilder.add(geoPointAtt); AttributeDescriptor geoShapeAtt; AttributeTypeBuilder geoShapeAttBuilder = new AttributeTypeBuilder(); geoShapeAttBuilder.setName("geom"); geoShapeAttBuilder.setBinding(Geometry.class); geoShapeAtt = geoShapeAttBuilder.buildDescriptor("geom", geoShapeAttBuilder.buildType()); geoShapeAtt.getUserData().put(GEOMETRY_TYPE, ElasticGeometryType.GEO_SHAPE); typeBuilder.add(geoShapeAtt); AttributeDescriptor analyzedAtt; AttributeTypeBuilder analyzedAttBuilder = new AttributeTypeBuilder(); analyzedAttBuilder.setName("analyzed"); analyzedAttBuilder.setBinding(String.class); analyzedAtt = analyzedAttBuilder.buildDescriptor("analyzed", analyzedAttBuilder.buildType()); analyzedAtt.getUserData().put(ANALYZED, true); typeBuilder.add(analyzedAtt); AttributeDescriptor netsedAtt; AttributeTypeBuilder nestedAttBuilder = new AttributeTypeBuilder(); nestedAttBuilder.setName("nested.hej"); nestedAttBuilder.setBinding(String.class); netsedAtt = nestedAttBuilder.buildDescriptor("nested.hej", nestedAttBuilder.buildType()); netsedAtt.getUserData().put(NESTED, true); netsedAtt.getUserData().put(ANALYZED, true); typeBuilder.add(netsedAtt); AttributeDescriptor netsedDateAtt; AttributeTypeBuilder nestedDateAttBuilder = new AttributeTypeBuilder(); nestedDateAttBuilder.setName("nested.datehej"); nestedDateAttBuilder.setBinding(Date.class); netsedDateAtt = nestedDateAttBuilder.buildDescriptor("nested.datehej", nestedDateAttBuilder.buildType()); netsedDateAtt.getUserData().put(NESTED, true); typeBuilder.add(netsedDateAtt); featureType = typeBuilder.buildFeatureType(); setFilterBuilder(); parameters = new HashMap<>(); final Hints hints = new Hints(); hints.put(Hints.VIRTUAL_TABLE_PARAMETERS, parameters); query = new Query(); query.setHints(hints); dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); gf = new GeometryFactory(); }
Example 17
Source File: KMeansUtils.java From geowave with Apache License 2.0 | 4 votes |
public static DataTypeAdapter writeClusterCentroids( final KMeansModel clusterModel, final DataStorePluginOptions outputDataStore, final String centroidAdapterName, final ScaledTemporalRange scaledRange) { final SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName(centroidAdapterName); typeBuilder.setNamespaceURI(BasicFeatureTypes.DEFAULT_NAMESPACE); try { typeBuilder.setCRS(CRS.decode("EPSG:4326", true)); } catch (final FactoryException fex) { LOGGER.error(fex.getMessage(), fex); } final AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder(); typeBuilder.add( attrBuilder.binding(Geometry.class).nillable(false).buildDescriptor( Geometry.class.getName().toString())); if (scaledRange != null) { typeBuilder.add(attrBuilder.binding(Date.class).nillable(false).buildDescriptor("Time")); } typeBuilder.add( attrBuilder.binding(Integer.class).nillable(false).buildDescriptor("ClusterIndex")); final SimpleFeatureType sfType = typeBuilder.buildFeatureType(); final SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sfType); final FeatureDataAdapter featureAdapter = new FeatureDataAdapter(sfType); final DataStore featureStore = outputDataStore.createDataStore(); final Index featureIndex = new SpatialDimensionalityTypeProvider().createIndex(new SpatialOptions()); featureStore.addType(featureAdapter, featureIndex); try (Writer writer = featureStore.createWriter(featureAdapter.getTypeName())) { for (final Vector center : clusterModel.clusterCenters()) { final int index = clusterModel.predict(center); final double lon = center.apply(0); final double lat = center.apply(1); sfBuilder.set( Geometry.class.getName(), GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(lon, lat))); if ((scaledRange != null) && (center.size() > 2)) { final double timeVal = center.apply(2); final Date time = scaledRange.valueToTime(timeVal); sfBuilder.set("Time", time); LOGGER.warn("Write time: " + time); } sfBuilder.set("ClusterIndex", index); final SimpleFeature sf = sfBuilder.buildFeature("Centroid-" + index); writer.write(sf); } } return featureAdapter; }
Example 18
Source File: Stanag4676Utils.java From geowave with Apache License 2.0 | 4 votes |
public static SimpleFeatureType createTrackDataType() { final SimpleFeatureTypeBuilder simpleFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); simpleFeatureTypeBuilder.setName(TRACK); simpleFeatureTypeBuilder.setNamespaceURI(NAMESPACE); final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder(); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(LineString.class).buildDescriptor("geometry")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(LineString.class).buildDescriptor("DetailGeometry")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).buildDescriptor("Mission")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).buildDescriptor("TrackNumber")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).buildDescriptor("TrackUUID")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Date.class).buildDescriptor("StartTime")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Date.class).buildDescriptor("EndTime")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("Duration")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("MinSpeed")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("MaxSpeed")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("AvgSpeed")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("Distance")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("StartLatitude")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("StartLongitude")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("EndLatitude")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("EndLongitude")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("DetailStartLatitude")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("DetailStartLongitude")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("DetailEndLatitude")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("DetailEndLongitude")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Integer.class).buildDescriptor("PointCount")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Integer.class).buildDescriptor("EventCount")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).buildDescriptor("TrackStatus")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Integer.class).buildDescriptor("TurnCount")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Integer.class).buildDescriptor("UTurnCount")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Integer.class).buildDescriptor("StopCount")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("StopDuration")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).buildDescriptor("AvgStopDuration")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).buildDescriptor("Classification")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).buildDescriptor("ObjectClass")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).buildDescriptor("ObjectClassConf")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).buildDescriptor("ObjectClassRel")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).buildDescriptor("ObjectClassTime")); simpleFeatureTypeBuilder.setDefaultGeometry("geometry"); final TimeDescriptorConfiguration timeConfig = new TimeDescriptorConfiguration(); timeConfig.setStartRangeName("StartTime"); timeConfig.setEndRangeName("EndTime"); final SimpleFeatureType type = simpleFeatureTypeBuilder.buildFeatureType(); timeConfig.updateType(type); return type; }
Example 19
Source File: OmsLW03_NetworkHierarchyToPointsSplitter.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inNet); if (pGauklerStrickler < 10) { throw new ModelsIllegalargumentException("KS can't be negative.", this); } // Creates the list of contained features List<SimpleFeature> netList = FeatureUtilities.featureCollectionToList(inNet); // Creates the output feature collection DefaultFeatureCollection outNetPointsFC = new DefaultFeatureCollection(); // Creates the structure of the output point layer SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("net"); b.setCRS(inNet.getBounds().getCoordinateReferenceSystem()); b.add("the_geom", Point.class); b.add(PFAF, String.class); b.add(LINKID, Integer.class); b.add(GAUKLER, Double.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); /*for each line generates the points geometries of the contained * vertexes with attributes -> it is assumed that the input network is * the output of the tool NetworkAttributesBuilder */ for( SimpleFeature netLineFeature : netList ) { int count = 1; Object pfaf = netLineFeature.getAttribute(PFAF); Geometry netLine = (Geometry) netLineFeature.getDefaultGeometry(); for( int i = 0; i < netLine.getNumGeometries(); i++ ) { LineString net = (LineString) netLine.getGeometryN(i); Coordinate[] coordinates = net.getCoordinates(); for( int j = 0; j < coordinates.length - 1; j++ ) { Point point = gf.createPoint(coordinates[j]); Object[] values = new Object[]{point, pfaf, count, pGauklerStrickler}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(null); outNetPointsFC.add(feature); count++; } } } outNetPoints = outNetPointsFC; }
Example 20
Source File: CreateSampleDataTest.java From sldeditor with GNU General Public License v3.0 | 3 votes |
/** Test method for {@link com.sldeditor.datasource.impl.CreateSampleData#getDataStore()}. */ @Test public void testGetDataStore() { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); String typeName = "test type name"; b.setName(typeName); String namespace = null; b.setNamespaceURI(namespace); // add a geometry property b.setCRS(DefaultGeographicCRS.WGS84); // set crs first b.add("the_geom", Polygon.class); b.setDefaultGeometry("the_geom"); // Build the feature type SimpleFeatureType schema = b.buildFeatureType(); CreateSampleData sampleData = new CreateSampleData(); sampleData.create(null, null); sampleData.create(schema, null); DataStore dataStore = sampleData.getDataStore(); assertTrue(dataStore != null); assertEquals(GeometryTypeEnum.POLYGON, sampleData.getGeometryType()); }