@Override public String resolve(double x, double y) { System.out.println("x="+x+", y="+y); FeatureIterator<Feature> iterator = collection.features(); while( iterator.hasNext() ){ SimpleFeature feature = (SimpleFeature) iterator.next(); Geometry geom = (Geometry) feature.getDefaultGeometry(); GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); Coordinate coord = new Coordinate(x, y); Point point = geometryFactory.createPoint(coord); //System.out.println("checking "+point.toString()); if(geom.contains(point)) { return feature.getAttribute(this.nameField).toString(); } } return null; }
MathTransform toMeters = CRS.findMathTransform(wgs, crs, false); MathTransform fromMeters = CRS.findMathTransform(crs, wgs, false); GeometryFactory geomf = JTSFactoryFinder.getGeometryFactory();
/** * Returns the first implementation of {@link GeometryFactory}, a new one is created if possible * or an exception is thrown otherwise. * * @return The first geometry factory available on the classpath * @throws FactoryRegistryException if no implementation was found or can be created for the * {@link GeometryFactory} category. */ public static synchronized GeometryFactory getGeometryFactory() throws FactoryRegistryException { return getGeometryFactory(null); } /**
/** Creates a reader that creates objects using the default {@link GeometryFactory}. */ public WKTReader2() { this(JTSFactoryFinder.getGeometryFactory(null)); }
/** * Returns the first implementation of {@link GeometryFactory} matching the specified hints. If * no implementation matches, a new one is created if possible or an exception is thrown * otherwise. * * <p>Hints that may be understood includes {@link Hints#JTS_COORDINATE_SEQUENCE_FACTORY * JTS_COORDINATE_SEQUENCE_FACTORY}, {@link Hints#JTS_PRECISION_MODEL JTS_PRECISION_MODEL} and * {@link Hints#JTS_SRID JTS_SRID}. * * @param hints An optional map of hints, or {@code null} if none. * @return The first geometry factory that matches the supplied hints. * @throws FactoryRegistryException if no implementation was found or can be created for the * {@link GeometryFactory} category and the given hints. */ public static synchronized GeometryFactory getGeometryFactory(Hints hints) throws FactoryRegistryException { return JTSFactoryFinder.getGeometryFactory(hints); }
/** Creates a reader that creates objects using the default {@link GeometryFactory}. */ public WKTReader2(double tolerance) { this(new CurvedGeometryFactory(JTSFactoryFinder.getGeometryFactory(null), tolerance)); }
@Test public void testJTSFactory() { GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null); assertNotNull(gf); }
private static GeometryFactory getGeometryFactory() { if (geometryFactory != null) { return geometryFactory; } else { return (geometryFactory = JTSFactoryFinder.getGeometryFactory(null)); } }
/** * Returns the first implementation of {@link GeometryFactory}, a new one is created if * possible or an exception is thrown otherwise. * * @return The first geometry factory available on the classpath * @throws FactoryRegistryException if no implementation was found or can be created for the * {@link GeometryFactory} category. */ public static synchronized GeometryFactory getGeometryFactory() throws FactoryRegistryException { return getGeometryFactory(null); } /**
/** * Creates a reader that creates objects using the default {@link GeometryFactory}. */ public WKTReader2() { this(JTSFactoryFinder.getGeometryFactory( null )); }
public void testGraphicLegendRotation() throws Exception { FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(); GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(); // Load image directly from file, for comparison with painter output final URL imageURL = TestData.getResource(this, "icon64.png"); final BufferedImage testImage = ImageIO.read(imageURL); final int width = testImage.getWidth(); final int height = testImage.getHeight(); // Get graphic legend from style final Style style = RendererBaseTest.loadStyle(this, "testGraphicLegend.sld"); final Rule rule = style.featureTypeStyles().get(0).rules().get(0); final GraphicLegend legend = (GraphicLegend) rule.getLegend(); // Set rotation to 45 degrees legend.setRotation(ff.literal(45.0)); // Paint legend using StyledShapePainter final Point point = gf.createPoint(new Coordinate(width / 2, height / 2)); final LiteShape2 shape = new LiteShape2(point, null, null, false); int imageType = testImage.getType(); if (imageType == BufferedImage.TYPE_CUSTOM) { imageType = BufferedImage.TYPE_INT_RGB; } final BufferedImage paintedImage = new BufferedImage(width, height, imageType); final Graphics2D graphics = paintedImage.createGraphics(); final StyledShapePainter painter = new StyledShapePainter(); painter.paint(graphics, shape, legend, 1, false); graphics.dispose(); // Ensure painted legend does not match image from file Assert.assertFalse(imagesIdentical(paintedImage, testImage)); }
@Before public void setUp() throws Exception { SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.setName("render-test"); ftb.add("the_geom", Point.class, DefaultGeographicCRS.WGS84); ftb.setDefaultGeometry("the_geom"); ftb.add("name", String.class); featureType = ftb.buildFeatureType(); GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(); SimpleFeatureBuilder fb = new SimpleFeatureBuilder(featureType); fb.set("the_geom", gf.createPoint(new Coordinate(10, 10))); fb.set("name", "The name"); feature = fb.buildFeature(null); File shpFile = new File( "./target/screenMapTest/" + feature.getFeatureType().getName().getLocalPart() + ".shp"); shpFile.getParentFile().mkdirs(); ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory(); Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put(ShapefileDataStoreFactory.URLP.key, shpFile.toURI().toURL()); shapeFileDataStore = dataStoreFactory.createNewDataStore(params); shapeFileDataStore.createSchema(feature.getFeatureType()); SimpleFeatureStore featureStore = (SimpleFeatureStore) shapeFileDataStore.getFeatureSource(shapeFileDataStore.getTypeNames()[0]); featureStore.addFeatures(DataUtilities.collection(feature)); RendererBaseTest.setupVeraFonts(); }
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); WKTReader reader = new WKTReader(geometryFactory); Polygon geom = (Polygon) reader.read("POLYGON ((0 2, 1 0, 1 1, 0 1, 0 2))");
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); WKTReader reader = new WKTReader(geometryFactory); Polygon geom = (Polygon) reader.read("POLYGON ((0 2, 1 0, 1 1, 0 1, 0 2))");
private static Geometry combineIntoOneGeometry(final Collection<Geometry> geometries) { final GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(null); // note the following geometry collection may be invalid (say with // overlapping polygons) final Geometry geometryCollection = factory.buildGeometry(geometries); // try { return geometryCollection.union(); // } // catch (Exception e) { // LOGGER.warn("Error creating a union of this geometry collection", e); // return geometryCollection; // } }
@Override public Geometry getBoundingBox() { if (getInternalGrid() == null) { LOGGER.warning("FIXME: getBoundingBox called while grid is null"); return null; } if (boundingBox == null) { LOGGER.finest("Initializing bounding box for Grid"); boundingBox = JTS.toGeometry((BoundingBox)getInternalGrid().getEnvelope2D(), JTSFactoryFinder.getGeometryFactory(null)); } return boundingBox; }
public static void createPolygon(List<Coordinate> coords, File output) { List<SimpleFeature> features = new ArrayList<>(); final SimpleFeatureType type = createFeatureType(); // final SimpleFeatureType type = BasicFeatureTypes.POLYGON; GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(); SimpleFeatureBuilder f = new SimpleFeatureBuilder(type); f.add(gf.createPolygon(coords.toArray(new Coordinate[] {}))); SimpleFeature feature = f.buildFeature(null); features.add(feature); saveFeaturesToShapefile(features, type, output); }
@Override public Point getCentroid() { if (getInternalGrid() == null) { LOGGER.warning("FIXME:getCentroid called while grid is null"); return null; } if (centroid == null) { Double x = getInternalGrid().getEnvelope2D().getCenterX(); Double y = getInternalGrid().getEnvelope2D().getCenterY(); centroid = JTSFactoryFinder.getGeometryFactory(null).createPoint(new Coordinate(x, y)); } return centroid; }
@Override public Point getCentroid() { if (getInternalGrid() == null) { LOGGER.warning("FIXME:getCentroid called while grid is null"); return null; } if (centroid == null) { Double x = getInternalGrid().getEnvelope2D().getCenterX(); Double y = getInternalGrid().getEnvelope2D().getCenterY(); centroid = new Point(new CoordinateArraySequence(new Coordinate[]{new Coordinate(x, y)}), JTSFactoryFinder.getGeometryFactory(null)); } return centroid; }
public CSVFeatureReader(ContentState contentState) throws IOException { this.state = contentState; CSVDataStore csv = (CSVDataStore) contentState.getEntry().getDataStore(); reader = csv.read(); // this may throw an IOException if it could not connect boolean header = reader.readHeaders(); if (! header ){ throw new IOException("Unable to read csv header"); } builder = new SimpleFeatureBuilder( state.getFeatureType() ); geometryFactory = JTSFactoryFinder.getGeometryFactory(null); row = 0; }