org.geotools.feature.simple.SimpleFeatureTypeBuilder Java Examples
The following examples show how to use
org.geotools.feature.simple.SimpleFeatureTypeBuilder.
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: Shape.java From constellation with Apache License 2.0 | 6 votes |
private static SimpleFeatureType generateFeatureType(final String uuid, final String srs, final String geometryName, final Class<? extends Geometry> geometryClass, final Map<String, Class<?>> attributes) { final SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder(); featureTypeBuilder.setName(uuid); featureTypeBuilder.setSRS(srs); featureTypeBuilder.add(geometryName, geometryClass); featureTypeBuilder.add(NAME_ATTRIBUTE, String.class); featureTypeBuilder.add(CENTROID_LATITUDE_ATTRIBUTE, Double.class); featureTypeBuilder.add(CENTROID_LONGITUDE_ATTRIBUTE, Double.class); featureTypeBuilder.add(RADIUS_ATTRIBUTE, Double.class); if (attributes != null) { attributes.forEach(featureTypeBuilder::add); } return featureTypeBuilder.buildFeatureType(); }
Example #2
Source File: SchemaConverter.java From geowave with Apache License 2.0 | 6 votes |
public static SimpleFeatureType schemaToFeatureType( final StructType schema, final String typeName) { final SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName(typeName); typeBuilder.setNamespaceURI(BasicFeatureTypes.DEFAULT_NAMESPACE); try { typeBuilder.setCRS(CRS.decode("EPSG:4326", true)); } catch (final FactoryException e) { LOGGER.error(e.getMessage(), e); } final AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder(); for (final StructField field : schema.fields()) { final AttributeDescriptor attrDesc = attrDescFromStructField(attrBuilder, field); typeBuilder.add(attrDesc); } return typeBuilder.buildFeatureType(); }
Example #3
Source File: BandFeatureIterator.java From geowave with Apache License 2.0 | 6 votes |
private void init(final Filter cqlFilter) throws NoSuchAuthorityCodeException, FactoryException { final SimpleFeatureTypeBuilder typeBuilder = sceneIterator.getProvider().bandFeatureTypeBuilder(); final SimpleFeatureType bandType = typeBuilder.buildFeatureType(); Iterator<SimpleFeature> featureIterator = new FeatureIteratorIterator<>(sceneIterator); featureIterator = Iterators.concat( Iterators.transform(featureIterator, new SceneToBandFeatureTransform(bandType))); if ((cqlFilter != null) && !cqlFilter.equals(Filter.INCLUDE)) { final String[] attributes = DataUtilities.attributeNames(cqlFilter, bandType); // we can rely on the scene filtering if we don't have to check any // specific band filters if (ArrayUtils.contains(attributes, BAND_ATTRIBUTE_NAME)) { featureIterator = Iterators.filter( featureIterator, new SceneFeatureIterator.CqlFilterPredicate(cqlFilter)); } } iterator = featureIterator; }
Example #4
Source File: FeatureGeometrySubstitutor.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * @param oldFeatureType the {@link FeatureType} of the existing features. * @throws FactoryRegistryException * @throws SchemaException */ public FeatureGeometrySubstitutor( SimpleFeatureType oldFeatureType, Class< ? > newGeometryType ) throws Exception { List<AttributeDescriptor> oldAttributeDescriptors = oldFeatureType.getAttributeDescriptors(); // create the feature type SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName(oldFeatureType.getName()); b.setCRS(oldFeatureType.getCoordinateReferenceSystem()); if (newGeometryType == null) { b.addAll(oldAttributeDescriptors); } else { for( AttributeDescriptor attributeDescriptor : oldAttributeDescriptors ) { if (attributeDescriptor instanceof GeometryDescriptor) { b.add("the_geom", newGeometryType); } else { b.add(attributeDescriptor); } } } newFeatureType = b.buildFeatureType(); }
Example #5
Source File: OmsLasConverter.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private void createBboxGeometry( CoordinateReferenceSystem crs, File lasFile, SimpleFeatureCollection outGeodata ) throws Exception { final ReferencedEnvelope3D envelope = lasReader.getHeader().getDataEnvelope(); ReferencedEnvelope env2d = new ReferencedEnvelope(envelope); final Polygon polygon = FeatureUtilities.envelopeToPolygon(new Envelope2D(env2d)); final SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("lasdataenvelope"); b.setCRS(crs); b.add("the_geom", Polygon.class); b.add("id", String.class); final SimpleFeatureType type = b.buildFeatureType(); final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); final Object[] values = new Object[]{polygon, lasFile.getName()}; builder.addAll(values); final SimpleFeature feature = builder.buildFeature(null); ((DefaultFeatureCollection) outGeodata).add(feature); OmsVectorWriter.writeVector(outFile, outGeodata); }
Example #6
Source File: OmsGridsGenerator.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private void createPoints( CoordinateReferenceSystem crs, GeometryFactory gf, List<LineString> verticals, List<LineString> horizontals ) { outMap = new DefaultFeatureCollection(); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName(POINT); b.setCRS(crs); b.add("the_geom", Point.class); b.add("id", Long.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(type); Geometry gVer = gf.createMultiLineString(verticals.toArray(new LineString[0])); Geometry gHor = gf.createMultiLineString(horizontals.toArray(new LineString[0])); Geometry intersection = gHor.intersection(gVer); long index = 0; int numGeometries = intersection.getNumGeometries(); for( int i = 0; i < numGeometries; i++ ) { Geometry geometry = intersection.getGeometryN(i); Object[] values = new Object[]{geometry, index++}; fbuilder.addAll(values); SimpleFeature feature = fbuilder.buildFeature(null); ((DefaultFeatureCollection) outMap).add(feature); } }
Example #7
Source File: TestFeatureUtils.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("nls") public void testFeatureUtils() throws Exception { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("typename"); b.setCRS(DefaultGeographicCRS.WGS84); b.add("the_geom", Point.class); b.add("AttrName", String.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Object[] values = new Object[]{GeometryUtilities.gf().createPoint(new Coordinate(0, 0)), "test"}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(type.getTypeName()); Object attr = FeatureUtilities.getAttributeCaseChecked(feature, "attrname"); assertEquals("test", attr.toString()); attr = FeatureUtilities.getAttributeCaseChecked(feature, "attrnam"); assertNull(attr); }
Example #8
Source File: FeatureDataUtils.java From geowave with Apache License 2.0 | 6 votes |
public static FeatureDataAdapter cloneFeatureDataAdapter( final DataStorePluginOptions storeOptions, final String originalTypeName, final String newTypeName) { // Get original feature type info final SimpleFeatureType oldType = FeatureDataUtils.getFeatureType(storeOptions, originalTypeName); // Build type using new name final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder(); sftBuilder.init(oldType); sftBuilder.setName(newTypeName); final SimpleFeatureType newType = sftBuilder.buildFeatureType(); // Create new adapter that will use new typename final FeatureDataAdapter newAdapter = new FeatureDataAdapter(newType); return newAdapter; }
Example #9
Source File: AdaptiveTinFilter.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private SimpleFeatureCollection featureCollectionFromNonGroundCoordinates( CoordinateReferenceSystem crs, List<Coordinate> nonGroundCoordinateList ) { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("nongroundpoints"); b.setCRS(crs); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); b.add("the_geom", Point.class); b.add("elev", Double.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); for( Coordinate c : nonGroundCoordinateList ) { Point g = gf.createPoint(c); Object[] values = new Object[]{g, c.z}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(null); newCollection.add(feature); } return newCollection; }
Example #10
Source File: OmsZonalStats.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public static SimpleFeatureBuilder createFeatureBuilder( CoordinateReferenceSystem crs, boolean hasUserTotalMean ) { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("stats"); b.setCRS(crs); b.add("the_geom", Polygon.class); b.add(MIN, Double.class); b.add(MAX, Double.class); b.add(AVG, Double.class); b.add(VAR, Double.class); b.add(SDEV, Double.class); b.add(SUM, Double.class); if (hasUserTotalMean) b.add(AVGABSDEV, Double.class); b.add(ACTCELLS, Integer.class); b.add(INVCELLS, Integer.class); SimpleFeatureType type = b.buildFeatureType(); return new SimpleFeatureBuilder(type); }
Example #11
Source File: GeometryTranslator.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Builds a line feature from a dwg polyline 3D. * * TODO handle these as contourlines * */ public SimpleFeature convertDwgPolyline3D( String typeName, String layerName, DwgPolyline3D polyline3d, int id ) { double[][] ptos = polyline3d.getPts(); CoordinateList coordList = new CoordinateList(); if (ptos != null) { for( int j = 0; j < ptos.length; j++ ) { Coordinate coord = new Coordinate(ptos[j][0], ptos[j][1], ptos[j][2]); coordList.add(coord); } SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName(typeName); b.setCRS(crs); b.add(THE_GEOM, LineString.class); b.add(LAYER, String.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Geometry lineString = gF.createLineString(coordList.toCoordinateArray()); Object[] values = new Object[]{lineString, layerName}; builder.addAll(values); return builder.buildFeature(typeName + "." + id); } return null; }
Example #12
Source File: GeometryTranslator.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Builds a line feature from a dwg polyline 2D. * */ public SimpleFeature convertDwgLwPolyline( String typeName, String layerName, DwgLwPolyline lwPolyline, int id ) { Point2D[] ptos = lwPolyline.getVertices(); if (ptos != null) { CoordinateList coordList = new CoordinateList(); for( int j = 0; j < ptos.length; j++ ) { Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY(), 0.0); coordList.add(coord); } SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName(typeName); b.setCRS(crs); b.add(THE_GEOM, LineString.class); b.add(LAYER, String.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Geometry lineString = gF.createLineString(coordList.toCoordinateArray()); Object[] values = new Object[]{lineString, layerName}; builder.addAll(values); return builder.buildFeature(typeName + "." + id); } return null; }
Example #13
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 #14
Source File: ImportTrackAction.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private static SimpleFeatureType createTrackFeatureType(GeoCoding geoCoding) { SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.setName("org.esa.snap.TrackPoint"); /*0*/ ftb.add("pixelPos", Point.class, geoCoding.getImageCRS()); /*1*/ ftb.add("geoPos", Point.class, DefaultGeographicCRS.WGS84); /*2*/ ftb.add("data", Double.class); ftb.setDefaultGeometry(geoCoding instanceof CrsGeoCoding ? "geoPos" : "pixelPos"); // GeoTools Bug: this doesn't work // ftb.userData("trackPoints", "true"); final SimpleFeatureType ft = ftb.buildFeatureType(); ft.getUserData().put("trackPoints", "true"); return ft; }
Example #15
Source File: GeometryTranslator.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Builds a line feature from a dwg line. * */ public SimpleFeature convertDwgLine( String typeName, String layerName, DwgLine line, int id ) { double[] p1 = line.getP1(); double[] p2 = line.getP2(); Point2D[] ptos = new Point2D[]{new Point2D.Double(p1[0], p1[1]), new Point2D.Double(p2[0], p2[1])}; CoordinateList coordList = new CoordinateList(); for( int j = 0; j < ptos.length; j++ ) { Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY(), 0.0); coordList.add(coord); } SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName(typeName); b.setCRS(crs); b.add(THE_GEOM, LineString.class); b.add(LAYER, String.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Geometry lineString = gF.createLineString(coordList.toCoordinateArray()); Object[] values = new Object[]{lineString, layerName}; builder.addAll(values); return builder.buildFeature(typeName + "." + id); }
Example #16
Source File: GeoLifeUtils.java From geowave with Apache License 2.0 | 6 votes |
public static SimpleFeatureType createGeoLifeTrackDataType() { final SimpleFeatureTypeBuilder simpleFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); simpleFeatureTypeBuilder.setName(GEOLIFE_TRACK_FEATURE); final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder(); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Geometry.class).nillable(true).buildDescriptor("geometry")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Date.class).nillable(true).buildDescriptor("StartTimeStamp")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Date.class).nillable(true).buildDescriptor("EndTimeStamp")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Long.class).nillable(true).buildDescriptor("Duration")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Long.class).nillable(true).buildDescriptor("NumberPoints")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("TrackId")); return simpleFeatureTypeBuilder.buildFeatureType(); }
Example #17
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 #18
Source File: GeoWaveAvroFeatureDataAdapterTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void testCRSProjecttioin() { final SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName("test"); typeBuilder.setCRS(GeometryUtils.getDefaultCRS()); // <- Coordinate // reference // add attributes in order typeBuilder.add("geom", Point.class); typeBuilder.add("name", String.class); typeBuilder.add("count", Long.class); // build the type final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(typeBuilder.buildFeatureType()); final GeoWaveAvroFeatureDataAdapter dataAdapter = new GeoWaveAvroFeatureDataAdapter( builder.getFeatureType(), new GlobalVisibilityHandler<SimpleFeature, Object>("default")); final Index index = new SpatialIndexBuilder().createIndex(); dataAdapter.init(index); final byte[] binary = dataAdapter.toBinary(); final GeoWaveAvroFeatureDataAdapter dataAdapterCopy = new GeoWaveAvroFeatureDataAdapter(); dataAdapterCopy.fromBinary(binary); assertEquals( dataAdapterCopy.getFeatureType().getCoordinateReferenceSystem().getCoordinateSystem(), GeometryUtils.getDefaultCRS().getCoordinateSystem()); }
Example #19
Source File: SimpleFeatureFigureFactoryTest.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@Before public void setUp() throws Exception { final SimpleFeatureTypeBuilder sftb = new SimpleFeatureTypeBuilder(); sftb.setName("someName"); sftb.add(PlainFeatureFactory.ATTRIB_NAME_STYLE_CSS, String.class); SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(sftb.buildFeatureType()); simpleFeature = sfb.buildFeature("someId"); }
Example #20
Source File: SceneFeatureIterator.java From geowave with Apache License 2.0 | 5 votes |
public static SimpleFeatureType createFeatureType() { // initialize the feature type final SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName(SCENES_TYPE_NAME); typeBuilder.setCRS(GeometryUtils.getDefaultCRS()); typeBuilder.add(SHAPE_ATTRIBUTE_NAME, MultiPolygon.class); typeBuilder.add(ENTITY_ID_ATTRIBUTE_NAME, String.class); typeBuilder.add(ACQUISITION_DATE_ATTRIBUTE_NAME, Date.class); typeBuilder.add(CLOUD_COVER_ATTRIBUTE_NAME, Float.class); typeBuilder.add(PROCESSING_LEVEL_ATTRIBUTE_NAME, String.class); typeBuilder.add(PATH_ATTRIBUTE_NAME, Integer.class); typeBuilder.add(ROW_ATTRIBUTE_NAME, Integer.class); typeBuilder.add(SCENE_DOWNLOAD_ATTRIBUTE_NAME, String.class); return typeBuilder.buildFeatureType(); }
Example #21
Source File: AnalyticFeature.java From geowave with Apache License 2.0 | 5 votes |
public static FeatureDataAdapter createFeatureAdapter( final String centroidDataTypeId, final String[] extraNumericDimensions, final String namespaceURI, final String SRID, final ClusterFeatureAttribute[] attributes, final Class<? extends Geometry> geometryClass) { try { final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(centroidDataTypeId); builder.setNamespaceURI( namespaceURI == null ? BasicFeatureTypes.DEFAULT_NAMESPACE : namespaceURI); builder.setSRS(SRID); builder.setCRS(CRS.decode(SRID, true)); for (final ClusterFeatureAttribute attrVal : attributes) { builder.add( attrVal.name, attrVal.equals(ClusterFeatureAttribute.GEOMETRY) ? geometryClass : attrVal.type); } for (final String extraDim : extraNumericDimensions) { builder.add(extraDim, Double.class); } final FeatureDataAdapter adapter = new FeatureDataAdapter(builder.buildFeatureType()); // TODO any consumers of this method will not be able to utilize // custom CRS adapter.init(new SpatialDimensionalityTypeProvider().createIndex(new SpatialOptions())); return adapter; } catch (final Exception e) { LOGGER.warn("Schema Creation Error. Hint: Check the SRID.", e); } return null; }
Example #22
Source File: OmsTrentoPProjectFilesGenerator.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Build the Calibration Type. * * @param crs * @return the type for the calibration shp. */ private SimpleFeatureType getCalibrationFeatureType( 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 node. 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()); // average slope b.add(values[10].getAttributeName(), values[10].getClazz()); // diameter to verify b.add(values[19].getAttributeName(), values[11].getClazz()); return b.buildFeatureType(); }
Example #23
Source File: Utility.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public static void makePolygonShp( ITrentoPType[] values, String path, CoordinateReferenceSystem crs, String pAreaShapeFileName, IHMProgressMonitor pm ) throws IOException { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); String typeName = values[0].getName(); b.setName(typeName); b.setCRS(crs); b.add("the_geom", Polygon.class); b.add(PipesTrentoP.ID.getAttributeName(), PipesTrentoP.ID.getClazz()); SimpleFeatureType areaType = b.buildFeatureType(); OmsShapefileFeatureWriter.writeEmptyShapefile(path, areaType, pm); }
Example #24
Source File: TestVectorTransformer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testVectorTransformer() 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); OmsVectorTransformer transformer = new OmsVectorTransformer(); transformer.inVector = newCollection; transformer.pTransX = 1.0; transformer.pTransY = -1.0; transformer.process(); SimpleFeatureCollection outFeatures = transformer.outVector; Geometry g = FeatureUtilities.featureCollectionToGeometriesList(outFeatures, false, null).get(0); Coordinate coord = g.getCoordinate(); assertEquals(coord.x, 1.0, 0.00001); assertEquals(coord.y, -1.0, 0.00001); }
Example #25
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Clones the given schema, changing the geometry attribute to match the given dimensionality. * * @param schema schema to clone * @param dimensionality dimensionality for the geometry 1= points, 2= lines, 3= polygons */ private FeatureType cloneWithDimensionality(FeatureType schema, int dimensionality) { SimpleFeatureType simpleFt = (SimpleFeatureType) schema; SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(schema.getName()); builder.setCRS(schema.getCoordinateReferenceSystem()); for (AttributeDescriptor desc : simpleFt.getAttributeDescriptors()) { if (isMixedGeometry(desc)) { GeometryDescriptor geomDescriptor = (GeometryDescriptor) desc; GeometryType geomType = geomDescriptor.getType(); Class<?> geometryClass = getGeometryForDimensionality(dimensionality); GeometryType gt = new GeometryTypeImpl( geomType.getName(), geometryClass, geomType.getCoordinateReferenceSystem(), geomType.isIdentified(), geomType.isAbstract(), geomType.getRestrictions(), geomType.getSuper(), geomType.getDescription()); builder.add( new GeometryDescriptorImpl( gt, geomDescriptor.getName(), geomDescriptor.getMinOccurs(), geomDescriptor.getMaxOccurs(), geomDescriptor.isNillable(), geomDescriptor.getDefaultValue())); } else { builder.add(desc); } } schema = builder.buildFeatureType(); return schema; }
Example #26
Source File: OmsEpanetProjectFilesGenerator.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private void makeLineLayer( IEpanetType[] types, File baseFolder, CoordinateReferenceSystem mapCrs ) throws MalformedURLException, IOException { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); String shapefileName = types[0].getShapefileName(); String typeName = types[0].getName(); b.setName(typeName); b.setCRS(mapCrs); b.add("the_geom", LineString.class); for( IEpanetType type : types ) { b.add(type.getAttributeName(), type.getClazz()); } SimpleFeatureType tanksType = b.buildFeatureType(); ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory(); File file = new File(baseFolder, shapefileName); Map<String, Serializable> create = new HashMap<String, Serializable>(); create.put("url", file.toURI().toURL()); ShapefileDataStore newDataStore = (ShapefileDataStore) factory.createNewDataStore(create); newDataStore.createSchema(tanksType); Transaction transaction = new DefaultTransaction(); SimpleFeatureStore featureStore = (SimpleFeatureStore) newDataStore.getFeatureSource(); featureStore.setTransaction(transaction); try { featureStore.addFeatures(new DefaultFeatureCollection()); transaction.commit(); } catch (Exception problem) { problem.printStackTrace(); transaction.rollback(); } finally { transaction.close(); } }
Example #27
Source File: OmsEpanetProjectFilesGenerator.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private void makePointLayer( IEpanetType[] types, File baseFolder, CoordinateReferenceSystem mapCrs ) throws MalformedURLException, IOException { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); String shapefileName = types[0].getShapefileName(); String typeName = types[0].getName(); b.setName(typeName); b.setCRS(mapCrs); b.add("the_geom", Point.class); for( IEpanetType type : types ) { b.add(type.getAttributeName(), type.getClazz()); } SimpleFeatureType tanksType = b.buildFeatureType(); ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory(); File file = new File(baseFolder, shapefileName); Map<String, Serializable> create = new HashMap<String, Serializable>(); create.put("url", file.toURI().toURL()); ShapefileDataStore newDataStore = (ShapefileDataStore) factory.createNewDataStore(create); newDataStore.createSchema(tanksType); Transaction transaction = new DefaultTransaction(); SimpleFeatureStore featureStore = (SimpleFeatureStore) newDataStore.getFeatureSource(); featureStore.setTransaction(transaction); try { featureStore.addFeatures(new DefaultFeatureCollection()); transaction.commit(); } catch (Exception problem) { problem.printStackTrace(); transaction.rollback(); } finally { transaction.close(); } }
Example #28
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 #29
Source File: ShapeFile.java From tutorials with MIT License | 5 votes |
static SimpleFeatureType createFeatureType() { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("Location"); builder.setCRS(DefaultGeographicCRS.WGS84); builder.add("Location", Point.class); builder.length(15) .add("Name", String.class); return builder.buildFeatureType(); }
Example #30
Source File: GeoWaveVisibilityIT.java From geowave with Apache License 2.0 | 5 votes |
private static SimpleFeatureType getType() { final SimpleFeatureTypeBuilder bldr = new SimpleFeatureTypeBuilder(); bldr.setName("testvis"); final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder(); bldr.add(attributeTypeBuilder.binding(String.class).buildDescriptor("a")); bldr.add(attributeTypeBuilder.binding(String.class).buildDescriptor("b")); bldr.add(attributeTypeBuilder.binding(String.class).buildDescriptor("c")); bldr.add(attributeTypeBuilder.binding(Point.class).nillable(false).buildDescriptor("geometry")); return bldr.buildFeatureType(); }