Java Code Examples for org.geotools.feature.simple.SimpleFeatureTypeBuilder#setName()
The following examples show how to use
org.geotools.feature.simple.SimpleFeatureTypeBuilder#setName() .
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: 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 3
Source File: TestProfile.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private SimpleFeatureCollection doCollection() { CoordinateReferenceSystem crs = HMTestMaps.getCrs(); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("typename"); b.setCRS(crs); b.add("the_geom", LineString.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Coordinate one = new Coordinate(westNorth.x + ep.getXres() / 2, centerCoord.y + ep.getYres() / 2); Coordinate two = new Coordinate(eastSouth.x - ep.getXres() / 2, centerCoord.y + ep.getYres() / 2); LineString lineString = GeometryUtilities.gf().createLineString(new Coordinate[]{one, two}); Object[] values = new Object[]{lineString}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(null); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); newCollection.add(feature); return newCollection; }
Example 4
Source File: GeoWaveKMeansIT.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: OmsDebrisVandre.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private SimpleFeatureType createPathType() { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("debrispaths"); b.setCRS(inFlow.getCoordinateReferenceSystem()); b.add("the_geom", LineString.class); b.add("ID", Integer.class); SimpleFeatureType type = b.buildFeatureType(); return type; }
Example 6
Source File: CQLQueryExample.java From geowave with Apache License 2.0 | 5 votes |
private static SimpleFeatureType getPointSimpleFeatureType() { final String NAME = "PointSimpleFeatureType"; final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder(); final AttributeTypeBuilder atBuilder = new AttributeTypeBuilder(); sftBuilder.setName(NAME); sftBuilder.add(atBuilder.binding(String.class).nillable(false).buildDescriptor("locationName")); sftBuilder.add(atBuilder.binding(Geometry.class).nillable(false).buildDescriptor("geometry")); return sftBuilder.buildFeatureType(); }
Example 7
Source File: TestVectorFieldRounder.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testVectorFieldRounder() throws Exception { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("test"); b.setCRS(DefaultGeographicCRS.WGS84); b.add("the_geom", Point.class); b.add("area", Double.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, 123.456789}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0"); newCollection.add(feature); OmsVectorFieldRounder rounder = new OmsVectorFieldRounder(); rounder.inVector = newCollection; rounder.fRound = "area"; rounder.pPattern = ".##"; rounder.process(); SimpleFeatureCollection outFeatures = rounder.outVector; SimpleFeature f = FeatureUtilities.featureCollectionToList(outFeatures).get(0); String areaStr = f.getAttribute("area").toString(); assertTrue(areaStr.equals("123.46")); }
Example 8
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 9
Source File: TwitterUtils.java From geowave with Apache License 2.0 | 5 votes |
public static SimpleFeatureType createTwitterEventDataType() { final SimpleFeatureTypeBuilder simpleFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); simpleFeatureTypeBuilder.setName(TWITTER_SFT_NAME); final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder(); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor( TWITTER_USERID_ATTRIBUTE)); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor( TWITTER_USERNAME_ATTRIBUTE)); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor( TWITTER_TEXT_ATTRIBUTE)); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor( TWITTER_INREPLYTOUSER_ATTRIBUTE)); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor( TWITTER_INREPLYTOSTATUS_ATTRIBUTE)); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Integer.class).nillable(true).buildDescriptor( TWITTER_RETWEETCOUNT_ATTRIBUTE)); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor( TWITTER_LANG_ATTRIBUTE)); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Date.class).nillable(false).buildDescriptor( TWITTER_DTG_ATTRIBUTE)); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Point.class).nillable(false).buildDescriptor( TWITTER_GEOMETRY_ATTRIBUTE)); return simpleFeatureTypeBuilder.buildFeatureType(); }
Example 10
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 11
Source File: GeometryDataSetGeneratorTest.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 12
Source File: GeoWaveAvroFeatureUtils.java From geowave with Apache License 2.0 | 5 votes |
public static SimpleFeatureType avroFeatureDefinitionToGTSimpleFeatureType( final AvroFeatureDefinition featureDefinition) throws ClassNotFoundException { final SimpleFeatureTypeBuilder sftb = new SimpleFeatureTypeBuilder(); sftb.setCRS(GeometryUtils.getDefaultCRS()); sftb.setName(featureDefinition.getFeatureTypeName()); final List<String> featureTypes = featureDefinition.getAttributeTypes(); final List<String> featureNames = featureDefinition.getAttributeNames(); for (int i = 0; i < featureDefinition.getAttributeNames().size(); i++) { final String type = featureTypes.get(i); final String name = featureNames.get(i); final Class<?> c = Class.forName(jtsCompatibility(type)); sftb.add(name, c); } return sftb.buildFeatureType(); }
Example 13
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 14
Source File: GpxUtils.java From geowave with Apache License 2.0 | 5 votes |
public static SimpleFeatureType createGPXRouteDataType() { final SimpleFeatureTypeBuilder simpleFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); simpleFeatureTypeBuilder.setName(GPX_ROUTE_FEATURE); final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder(); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Geometry.class).nillable(true).buildDescriptor("geometry")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Name")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Long.class).nillable(true).buildDescriptor("NumberPoints")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("TrackId")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Symbol")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("User")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Description")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Source")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Comment")); return simpleFeatureTypeBuilder.buildFeatureType(); }
Example 15
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 16
Source File: ALasDataManager.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
/** * Retrieve all the envelope features that intersect the geometry. * * <p>an elev attribute is added with the max elev contained in the envelope. * * @param checkGeom the {@link org.locationtech.jts.geom.Geometry} to use to check. * @param doOnlyEnvelope check for the geom envelope instead of a intersection with it. * @param minMaxZI an array to be filled with the [minz,maxz, minintensity, maxintensity] to be used as style. * @param doPoints if <code>true</code>, create points instead of polygons. * @return the features of the envelopes contained in the supplied geometry. * @throws Exception */ public synchronized SimpleFeatureCollection getEnvelopeFeaturesInGeometry( Geometry checkGeom, boolean doOnlyEnvelope, double[] minMaxZI, boolean doPoints ) throws Exception { List<Geometry> envelopesInGeometry = getEnvelopesInGeometry(checkGeom, doOnlyEnvelope, null); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("overview"); b.setCRS(crs); if (!doPoints) { b.add("the_geom", Polygon.class); } else { b.add("the_geom", Point.class); } b.add("elev", Double.class); b.add("intensity", Double.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); double minZ = Double.POSITIVE_INFINITY; double maxZ = Double.NEGATIVE_INFINITY; double minI = Double.POSITIVE_INFINITY; double maxI = Double.NEGATIVE_INFINITY; DefaultFeatureCollection newFeatures = new DefaultFeatureCollection(); for( int i = 0; i < envelopesInGeometry.size(); i++ ) { Geometry geom = envelopesInGeometry.get(i); if (doPoints) { Envelope envelope = geom.getEnvelopeInternal(); Coordinate centre = envelope.centre(); geom = gf.createPoint(centre); } double elev = -9999.0; double intens = -9999.0; Object userData = geom.getUserData(); if (userData instanceof double[]) { double[] data = (double[]) userData; elev = data[0]; intens = data[1]; } if (minMaxZI != null) { minZ = Math.min(minZ, elev); maxZ = Math.max(maxZ, elev); minI = Math.min(minI, intens); maxI = Math.max(maxI, intens); } Object[] objs = new Object[]{geom, elev, intens}; builder.addAll(objs); SimpleFeature feature = builder.buildFeature(null); newFeatures.add(feature); } if (minMaxZI != null) { minMaxZI[0] = minZ; minMaxZI[1] = maxZ; minMaxZI[2] = minI; minMaxZI[3] = maxI; } return newFeatures; }
Example 17
Source File: SpatialQueryExample.java From geowave with Apache License 2.0 | 4 votes |
private void ingestPointBasicFeature() { // First, we'll build our first kind of SimpleFeature, which we'll call // "basic-feature" // We need the type builder to build the feature type final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder(); // AttributeTypeBuilder for the attributes of the SimpleFeature final AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder(); // Here we're setting the SimpleFeature name. Later on, we'll be able to // query GW just by this particular feature. sftBuilder.setName("basic-feature"); // Add the attributes to the feature // Add the geometry attribute, which is mandatory for GeoWave to be able // to construct an index out of the SimpleFeature sftBuilder.add(attrBuilder.binding(Point.class).nillable(false).buildDescriptor("geometry")); // Add another attribute just to be able to filter by it in CQL sftBuilder.add(attrBuilder.binding(String.class).nillable(false).buildDescriptor("filter")); // Create the SimpleFeatureType final SimpleFeatureType sfType = sftBuilder.buildFeatureType(); // We need the adapter for all our operations with GeoWave final FeatureDataAdapter sfAdapter = new FeatureDataAdapter(sfType); // Now we build the actual features. We'll create two points. // First point final SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sfType); sfBuilder.set( "geometry", GeometryUtils.GEOMETRY_FACTORY.createPoint( new Coordinate(-80.211181640625, 25.848101000701597))); sfBuilder.set("filter", "Basic-Stadium"); // When calling buildFeature, we need to pass an unique id for that // feature, or it will be overwritten. final SimpleFeature basicPoint1 = sfBuilder.buildFeature("1"); // Construct the second feature. sfBuilder.set( "geometry", GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(-80.191360, 25.777804))); sfBuilder.set("filter", "Basic-College"); final SimpleFeature basicPoint2 = sfBuilder.buildFeature("2"); final ArrayList<SimpleFeature> features = new ArrayList<>(); features.add(basicPoint1); features.add(basicPoint2); // Ingest the data. For that purpose, we need the feature adapter, // the index type (the default spatial index is used here), // and an iterator of SimpleFeature ingest(sfAdapter, new SpatialIndexBuilder().createIndex(), features); }
Example 18
Source File: GpxUtils.java From geowave with Apache License 2.0 | 4 votes |
public static SimpleFeatureType createGPXPointDataType() { final SimpleFeatureTypeBuilder simpleFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); simpleFeatureTypeBuilder.setName(GPX_POINT_FEATURE); final AttributeTypeBuilder attributeTypeBuilder = new AttributeTypeBuilder(); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Geometry.class).nillable(true).buildDescriptor("geometry")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).nillable(true).buildDescriptor("Latitude")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).nillable(true).buildDescriptor("Longitude")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).nillable(true).buildDescriptor("Elevation")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Date.class).nillable(true).buildDescriptor("Timestamp")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Comment")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Integer.class).nillable(true).buildDescriptor("Satellites")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).nillable(true).buildDescriptor("VDOP")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).nillable(true).buildDescriptor("HDOP")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).nillable(true).buildDescriptor("PDOP")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Symbol")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor( "Classification")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).nillable(true).buildDescriptor("GeoHeight")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).nillable(true).buildDescriptor("Course")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Double.class).nillable(true).buildDescriptor( "MagneticVariation")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Source")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Link")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(String.class).nillable(true).buildDescriptor("Fix")); simpleFeatureTypeBuilder.add( attributeTypeBuilder.binding(Integer.class).nillable(true).buildDescriptor("Station")); return simpleFeatureTypeBuilder.buildFeatureType(); }
Example 19
Source File: TestVectorReader.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
public void testShapefileReader() 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(); for( int i = 0; i < 2; i++ ) { SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Point point = GeometryUtilities.gf().createPoint(new Coordinate(i, i)); Object[] values = new Object[]{point, i}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(type.getTypeName() + "." + i); newCollection.add(feature); } File tmpShape = File.createTempFile("testshp", ".shp"); if (tmpShape.exists()) { if (!tmpShape.delete()) throw new IOException(); } OmsVectorWriter writer = new OmsVectorWriter(); writer.file = tmpShape.getAbsolutePath(); writer.inVector = newCollection; writer.process(); // now read it again OmsVectorReader reader = new OmsVectorReader(); reader.file = tmpShape.getAbsolutePath(); reader.process(); SimpleFeatureCollection readFC = reader.outVector; FeatureIterator<SimpleFeature> featureIterator = readFC.features(); while( featureIterator.hasNext() ) { SimpleFeature f = featureIterator.next(); int id = ((Number) f.getAttribute("id")).intValue(); Geometry geometry = (Geometry) f.getDefaultGeometry(); Coordinate coordinate = geometry.getCoordinate(); if (id == 0) { assertEquals(coordinate.x, 0.0); assertEquals(coordinate.y, 0.0); } if (id == 1) { assertEquals(coordinate.x, 1.0); assertEquals(coordinate.y, 1.0); } if (id == 2) { assertEquals(coordinate.x, 2.0); assertEquals(coordinate.y, 2.0); } } if (tmpShape.exists()) { tmpShape.deleteOnExit(); } }
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()); }