当前位置: 首页>>代码示例>>Java>>正文


Java SimpleFeature.getDefaultGeometry方法代码示例

本文整理汇总了Java中org.opengis.feature.simple.SimpleFeature.getDefaultGeometry方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleFeature.getDefaultGeometry方法的具体用法?Java SimpleFeature.getDefaultGeometry怎么用?Java SimpleFeature.getDefaultGeometry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opengis.feature.simple.SimpleFeature的用法示例。


在下文中一共展示了SimpleFeature.getDefaultGeometry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: correctFeatures

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
public static SimpleFeatureCollection correctFeatures(SimpleFeatureCollection fc){
 	SimpleFeatureIterator iterator=fc.features();
 	DefaultFeatureCollection outVector = new DefaultFeatureCollection();

 	while(iterator.hasNext()){
 		SimpleFeature sf=iterator.next();
 		Geometry gm=(Geometry)sf.getDefaultGeometry();
 		if(!gm.isValid()){
 			gm=JTSUtil.repair(gm);
 			System.out.println(gm.isValid());
 		}
sf.setDefaultGeometry(gm);
   outVector.add(sf);

 	}

 	return fc;
 }
 
开发者ID:ec-europa,项目名称:sumo,代码行数:19,代码来源:SimpleShapefile.java

示例2: testCorrect3857Transform

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
/**
 * tests a coordinate transformation from epsg:4236 --> epsg:3857
 */
@Test
public void testCorrect3857Transform() {
    algo.setTargetEPSG("EPSG:3857");

    try {
        algo.runAlgorithm();
        FeatureCollection fc = algo.getResult();
        FeatureIterator<?> featureIterator = fc.features();
        SimpleFeature feature = (SimpleFeature) featureIterator.next();
        Geometry geometry = (Geometry) feature.getDefaultGeometry();
        Coordinate[] coords = geometry.getCoordinates();
        assertEquals(5781631.60732, coords[0].x, 0.001);
        assertEquals(1002058.9016, coords[0].y, 0.001);
        assertEquals(5364555.78035, coords[1].x, 0.001);
        assertEquals(908752.762799, coords[1].y, 0.001);
        assertEquals(5810127.070382, coords[2].x, 0.001);
        assertEquals(883747.339307, coords[2].y, 0.001);
        assertEquals(5770326.33379, coords[3].x, 0.001);
        assertEquals(861269.968343, coords[3].y, 0.001);
        assertEquals(5581093.09574, coords[4].x, 0.001);
        assertEquals(772727.762141, coords[4].y, 0.001);
    } catch (Exception e) {
        fail("Exception thrown: " + e.getMessage());
    }
}
 
开发者ID:52North,项目名称:javaps-geotools-backend,代码行数:29,代码来源:AlgorithmTest.java

示例3: CommunityAreas

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
public CommunityAreas() {
    communities = new HashMap<>();
    try {
        File f = new File(shapeFilePath);
        ShapefileDataStore shapefile = new ShapefileDataStore(f.toURI().toURL());

        SimpleFeatureIterator features = shapefile.getFeatureSource().getFeatures().features();
        SimpleFeature shp;
        while (features.hasNext()) {
            shp = features.next();
            int id = Integer.parseInt((String) shp.getAttribute("AREA_NUMBE"));
            String name = (String) shp.getAttribute("COMMUNITY");
            MultiPolygon boundary = (MultiPolygon) shp.getDefaultGeometry();
            CommunityArea ca = new CommunityArea(id, name, boundary);
            communities.put(id, ca);
        }
        features.close();
        shapefile.dispose();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:thekingofkings,项目名称:embedding,代码行数:23,代码来源:CommunityAreas.java

示例4: Tracts

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
public Tracts() {
    tracts = new HashMap<>();
    try {
        SimpleFeatureIterator features = getShapeFileFeatures();
        SimpleFeature shp;
        while (features.hasNext()) {
            shp = features.next();
            int id = Integer.parseInt((String) shp.getAttribute("tractce10"));
            MultiPolygon boundary = (MultiPolygon) shp.getDefaultGeometry();
            Tract t = new Tract(id, boundary);
            tracts.put(id, t);
        }
        features.close();
        shapefile.dispose();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:thekingofkings,项目名称:embedding,代码行数:19,代码来源:Tracts.java

示例5: testAllShapesArePolygon

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
public void testAllShapesArePolygon() {
    try {
        SimpleFeatureIterator features = Tracts.getShapeFileFeatures();
        SimpleFeature shp = features.next();

        int fieldSize = shp.getType().getTypes().size();
        assertEquals(fieldSize, 10);
        assertEquals(shp.getType().getType(3).getName().getLocalPart(), "tractce10");
        assertEquals(shp.getType().getType(0).getName().getLocalPart(), "MultiPolygon");
        for (int i = 0; i < fieldSize; i++){
            System.out.println(shp.getType().getType(i).getName().getLocalPart());
        }

        int cnt = 1;
        while (features.hasNext()) {
            shp = features.next();
            MultiPolygon g = (MultiPolygon) shp.getDefaultGeometry();
            cnt ++;
        }
        assertEquals(cnt, 801);
        features.close();
        Tracts.shapefile.dispose();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:thekingofkings,项目名称:embedding,代码行数:27,代码来源:TractsTest.java

示例6: fromSimpleFeature

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
public static GeoInfo fromSimpleFeature(SimpleFeature feature) {
    GeoInfo that = new GeoInfo();
    for (Property p: feature.getProperties()) {
        if (p.getName().toString().equals("NAME"))
            that.name = p.getValue().toString();
        if (p.getName().toString().equals("STATE"))
            that.state = p.getValue().toString();

        if (p.getName().toString().equals("COUNTY"))
            that.county = p.getValue().toString();

        if (p.getName().toString().equals("CITY"))
            that.city = p.getValue().toString();
    }

    that.multiPolygon = (MultiPolygon) feature.getDefaultGeometry();
    return that;
}
 
开发者ID:confluentinc,项目名称:strata-tutorials,代码行数:19,代码来源:GeoInfo.java

示例7: getValueAt

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
@Override
public Object getValueAt(int row, int column) {
    if ((row < 0) || (row >= getRowCount())) {
        return null;
    }

    if ((column < 0) || (column >= getColumnCount())) {
        return null;
    }

    SimpleFeature feature = getFeature(row);

    if (feature != null) {
        if (column == geometryFieldIndex) {
            Object defaultGeometry = feature.getDefaultGeometry();
            return defaultGeometry;
        } else {
            Object attributeData = feature.getAttribute(column);
            return attributeData;
        }
    }
    return null;
}
 
开发者ID:robward-scisys,项目名称:sldeditor,代码行数:24,代码来源:InLineFeatureModel.java

示例8: joinFeaures

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
/**
 *
 * @param shapes
 * @param shapes2
 * @throws Exception
 */
private static SimpleFeatureCollection joinFeaures(SimpleFeatureSource shapes, SimpleFeatureSource shapes2) throws Exception {
	SimpleFeatureCollection join =null;

    SimpleFeatureType schema = shapes.getSchema();
    String typeName = schema.getTypeName();
    String geomName = schema.getGeometryDescriptor().getLocalName();

    SimpleFeatureType schema2 = shapes2.getSchema();
    String typeName2 = schema2.getTypeName();
    String geomName2 = schema2.getGeometryDescriptor().getLocalName();
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();

    Query outerGeometry = new Query(typeName, Filter.INCLUDE, new String[] { geomName });
    SimpleFeatureCollection outerFeatures = shapes.getFeatures(outerGeometry);
    SimpleFeatureIterator iterator = outerFeatures.features();
    int max = 0;
    try {
        while (iterator.hasNext()) {
            SimpleFeature feature = iterator.next();
            try {
                Geometry geometry = (Geometry) feature.getDefaultGeometry();
                if (!geometry.isValid()) {
                    // skip bad data
                    continue;
                }
                Filter innerFilter = ff.intersects(ff.property(geomName2), ff.literal(geometry));
                Query innerQuery = new Query(typeName2, innerFilter, Query.NO_NAMES);
                join = shapes2.getFeatures(innerQuery);
                int size = join.size();
                max = Math.max(max, size);
            } catch (Exception skipBadData) {
            }
        }
    } finally {
        iterator.close();
    }
    return join;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:45,代码来源:SimpleShapefile.java

示例9: exportToShapefile

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
/**
 * Export features to a new shapefile using the map projection in which
 * they are currently displayed
 */
 public static void exportToShapefile(DataStore newDataStore, FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)/*,SimpleFeatureType ftype)*/ throws Exception {
 // carefully open an iterator and writer to process the results
    Transaction transaction = new DefaultTransaction();
    FeatureWriter<SimpleFeatureType, SimpleFeature> writer = newDataStore.getFeatureWriter(newDataStore.getTypeNames()[0],  transaction);

    FeatureIterator<SimpleFeature> iterator = featureCollection.features();
    try {

        while( iterator.hasNext() ){
            SimpleFeature feature = iterator.next();
            SimpleFeature copy = writer.next();


            //copy.setAttributes( feature.getAttributes() );
            Geometry geometry = (Geometry) feature.getDefaultGeometry();
            if(geometry!=null){
            	copy.setDefaultGeometry( geometry.buffer(0));
            	writer.write();
            }else{
            	logger.warn("Warning:geometry null");
            }
        }
        transaction.commit();
        logger.info("Export to shapefile complete" );
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
        logger.error("Export to shapefile failed",problem );
    } finally {
        writer.close();
        iterator.close();
        transaction.close();
    }
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:39,代码来源:SimpleShapefile.java

示例10: testCorrect4817Transform

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
/**
 * tests a coordinate transformation from epsg:4236 --> epsg:4817
 */
@Test
public void testCorrect4817Transform() {
    algo.setTargetEPSG("EPSG:4817");

    try {
        algo.runAlgorithm();
        FeatureCollection fc = algo.getResult();
        FeatureIterator<?> featureIterator = fc.features();
        SimpleFeature feature = (SimpleFeature) featureIterator.next();
        Geometry geometry = (Geometry) feature.getDefaultGeometry();
        Coordinate[] coords = geometry.getCoordinates();
        assertEquals(41.2178843506, coords[0].x, 0.001);
        assertEquals(8.95903973526, coords[0].y, 0.001);
        assertEquals(37.4710724824, coords[1].x, 0.001);
        assertEquals(8.13026146044, coords[1].y, 0.001);
        assertEquals(41.473842952, coords[2].x, 0.001);
        assertEquals(7.90771407361, coords[2].y, 0.001);
        assertEquals(41.1162889713, coords[3].x, 0.001);
        assertEquals(7.70767521468, coords[3].y, 0.001);
        assertEquals(39.4162959551, coords[4].x, 0.001);
        assertEquals(6.91879868251, coords[4].y, 0.001);
        FeatureCollection result = algo.getResult();
    } catch (Exception e) {
        fail("Exception thrown: " + e.getMessage());
    }
}
 
开发者ID:52North,项目名称:javaps-geotools-backend,代码行数:30,代码来源:AlgorithmTest.java

示例11: getTimeZone

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
private String getTimeZone(double lat, double lon){
    Point point = geometryFactory.createPoint(new Coordinate(lon,lat));
    List<Object> regions = quadtree.query(point.getEnvelopeInternal());
    for(Object o : regions){
        SimpleFeature feature = (SimpleFeature) o;
        Geometry geom = (Geometry) feature.getDefaultGeometry();
        if(point.within(geom)) {
            return (String)(feature.getAttribute("TZID"));
        }
    }
    throwError(BAD_REQUEST.getStatusCode(),"could not localize location " + lat + ", " + lon);
    return null;
}
 
开发者ID:graphhopper,项目名称:timezone,代码行数:14,代码来源:TimeZoneService.java

示例12: testAllShapesArePolygon

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
public void testAllShapesArePolygon() {
    try {
        File fin = new File(CommunityAreas.shapeFilePath);
        ShapefileDataStore r = new ShapefileDataStore(fin.toURI().toURL());
        SimpleFeatureType sft = r.getSchema();

        assertEquals(sft.getTypes().size(), 10);
        assertEquals(sft.getType(0).getName().getLocalPart(), "MultiPolygon");
        assertEquals(sft.getType(5).getName().getLocalPart(), "AREA_NUMBE");
        assertEquals(sft.getType(6).getName().getLocalPart(), "COMMUNITY");

        FeatureReader<SimpleFeatureType, SimpleFeature> fr = r.getFeatureReader();

        SimpleFeature shp;

        int total = 0;
        while (fr.hasNext()) {
            total ++;
            shp = fr.next();
            MultiPolygon g = (MultiPolygon) shp.getDefaultGeometry();
        }

        fr.close();
        r.dispose();

        assertEquals(total, 77);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:thekingofkings,项目名称:embedding,代码行数:31,代码来源:CommunityAreasTest.java

示例13: extractNormalizedGeometry

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
private Optional<Geometry> extractNormalizedGeometry(SimpleFeature feature, MathTransform crsTransform) throws TransformException {
    try {
        Geometry geom = (Geometry) feature.getDefaultGeometry();
        Geometry transformedGeom = JTS.transform(geom, crsTransform);
        transformedGeom.setSRID(Subject.SRID);
        return Optional.of(transformedGeom);
    } catch (ProjectionException e) {
        log.warn("Rejecting feature {}. You will see this if you have assertions enabled (e.g. " +
                "you run with `-ea`) as GeoTools runs asserts. See source of GeotoolsDataStoreUtils for details on this. " +
                "To fix this, replace `-ea` with `-ea -da:org.geotools...` in your test VM options (probably in" +
                "your IDE) to disable assertions in GeoTools.", feature.getID());
        return Optional.empty();
    }
}
 
开发者ID:FutureCitiesCatapult,项目名称:TomboloDigitalConnector,代码行数:15,代码来源:AbstractGeotoolsDataStoreImporter.java

示例14: updateFeature

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
public static void updateFeature(SimpleFeature feature) {
    Point point = (Point) feature.getDefaultGeometry();
    Double step = (Double) feature.getAttribute("step");

    Double newLong = nudgeLong(point.getX() + step);

    Geometry newPoint = WKTUtils$.MODULE$.read("POINT(" + newLong + " " + point.getY() + ")");

    feature.setAttribute("dtg", new Date());
    feature.setDefaultGeometry(newPoint);
}
 
开发者ID:geomesa,项目名称:geomesa-tutorials,代码行数:12,代码来源:KafkaLoadTester.java

示例15: prepareOperations

import org.opengis.feature.simple.SimpleFeature; //导入方法依赖的package包/类
/**
 * Filters operations and triggers the analysis
 */
private void prepareOperations(List<IVgiFeature> batch) {
	for (IVgiFeature feature : batch) {
		
		/** Filter by tag */
		if (!feature.filterByTag(settings.getFilterTag())) continue;
		
		if (settings.getCurrentPolygon() != null || settings.isWriteGeometryFiles()) {
			if (settings.getCurrentPolygon() != null) {
				if (!settings.getCurrentPolygon().getPolygon().getEnvelopeInternal().intersects(feature.getBBox())) continue;
			}
			
			SimpleFeature f = geometryAssemblerConsumer.assembleGeometry(feature, null);
			if (f == null) continue;
			
			if (((Geometry)f.getDefaultGeometry()).getGeometryType().equals("LineString")) {
				double length = GeomUtils.calculateLengthMeterFromWGS84LineStringAndoyer((LineString)f.getDefaultGeometry());
				f.setAttribute("length", length);
			}
			
			if (settings.getCurrentPolygon() != null) {
				Geometry geometry = (Geometry)f.getDefaultGeometry();
				if (geometry == null || geometry.disjoint(settings.getCurrentPolygon().getPolygon())) continue;					
			}
			
			if (settings.isWriteGeometryFiles()) {
				if (!mapFeatures.containsKey(f.getFeatureType())) mapFeatures.put(f.getFeatureType(), new DefaultFeatureCollection(f.getFeatureType().getTypeName(), f.getFeatureType()));
				if (!(boolean)f.getAttribute("deleted")) {
					mapFeatures.get(f.getFeatureType()).add(f);
				}
			}
		}
		
		featureList.add(feature);
	}
	
	analyzeFeatures();
}
 
开发者ID:SGroe,项目名称:vgi-analytics-framework,代码行数:41,代码来源:VgiAnalysisConsumer.java


注:本文中的org.opengis.feature.simple.SimpleFeature.getDefaultGeometry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。