@Test public void testConvertPolygonToPointArrayRounding() throws Exception { Polygon polygon = (Polygon) new WKTReader() .read( "POLYGON((-9.9 -9.9, -9.9 9.9, 9.9 9.9, 9.9 -9.9, -9.9 -9.9))"); java.awt.Polygon poly = FeatureUtilities.convertPolygonToPointArray( polygon, IdentityTransform.create(2), null); assertEquals(-10, poly.getBounds().x); assertEquals(-10, poly.getBounds().y); assertEquals(20, poly.getBounds().width); assertEquals(20, poly.getBounds().height); }
public static java.awt.Polygon convertPolygonToPointArray( final Polygon roiInput, MathTransform worldToGridTransform, List<Point2D> points) throws TransformException { final boolean isIdentity = worldToGridTransform.isIdentity(); final double[] coords = new double[2]; final LineString exteriorRing = roiInput.getExteriorRing(); final CoordinateSequence exteriorRingCS = exteriorRing.getCoordinateSequence(); final int numCoords = exteriorRingCS.size(); final java.awt.Polygon retValue = new java.awt.Polygon(); for (int i = 0; i < numCoords; i++) { coords[0] = exteriorRingCS.getX(i); coords[1] = exteriorRingCS.getY(i); if (!isIdentity) worldToGridTransform.transform(coords, 0, coords, 0, 1); final int x = (int) Math.round(coords[0]); final int y = (int) Math.round(coords[1]); if (points != null) points.add(new Point2D.Double(coords[0], coords[1])); retValue.addPoint(x, y); } return retValue; }
FeatureUtilities { public static java.awt.Polygon convertPolygonToPointArray( final Polygon roiInput, MathTransform worldToGridTransform, List<Point2D> points) throws TransformException { final boolean isIdentity = worldToGridTransform.isIdentity(); final double[] coords = new double[2]; final LineString exteriorRing = roiInput.getExteriorRing(); final CoordinateSequence exteriorRingCS = exteriorRing.getCoordinateSequence(); final int numCoords = exteriorRingCS.size(); final java.awt.Polygon retValue = new java.awt.Polygon(); for (int i = 0; i < numCoords; i++) { coords[0] = exteriorRingCS.getX(i); coords[1] = exteriorRingCS.getY(i); if (!isIdentity) worldToGridTransform.transform(coords, 0, coords, 0, 1); final int x = (int) Math.round(coords[0]); final int y = (int) Math.round(coords[1]); if (points != null) points.add(new Point2D.Double(coords[0], coords[1])); retValue.addPoint(x, y); } return retValue; } }
FeatureUtilities { public static java.awt.Polygon convertPolygonToPointArray( final Polygon roiInput, MathTransform worldToGridTransform, List<Point2D> points) throws TransformException { final boolean isIdentity = worldToGridTransform.isIdentity(); final double[] coords = new double[2]; final LineString exteriorRing = roiInput.getExteriorRing(); final CoordinateSequence exteriorRingCS = exteriorRing.getCoordinateSequence(); final int numCoords = exteriorRingCS.size(); final java.awt.Polygon retValue = new java.awt.Polygon(); for (int i = 0; i < numCoords; i++) { coords[0] = exteriorRingCS.getX(i); coords[1] = exteriorRingCS.getY(i); if (!isIdentity) worldToGridTransform.transform(coords, 0, coords, 0, 1); final int x = (int) Math.round(coords[0]); final int y = (int) Math.round(coords[1]); if (points != null) points.add(new Point2D.Double(coords[0], coords[1])); retValue.addPoint(x, y); } return retValue; } private  FeatureUtilities(); }
FeatureUtilities { public static java.awt.Polygon convertPolygonToPointArray( final Polygon roiInput, MathTransform worldToGridTransform, List<Point2D> points) throws TransformException { final boolean isIdentity = worldToGridTransform.isIdentity(); final double[] coords = new double[2]; final LineString exteriorRing = roiInput.getExteriorRing(); final CoordinateSequence exteriorRingCS = exteriorRing.getCoordinateSequence(); final int numCoords = exteriorRingCS.size(); final java.awt.Polygon retValue = new java.awt.Polygon(); for (int i = 0; i < numCoords; i++) { coords[0] = exteriorRingCS.getX(i); coords[1] = exteriorRingCS.getY(i); if (!isIdentity) worldToGridTransform.transform(coords, 0, coords, 0, 1); final int x = (int) Math.round(coords[0]); final int y = (int) Math.round(coords[1]); if (points != null) points.add(new Point2D.Double(coords[0], coords[1])); retValue.addPoint(x, y); } return retValue; } private  FeatureUtilities(); static Polygon getPolygon(final Rectangle2D rect, final int srid); @SuppressWarnings("unchecked") static SimpleFeatureCollection wrapGridCoverage(final GridCoverage2D coverage); static boolean isWrappedCoverage(SimpleFeatureType featureType); @SuppressWarnings("unchecked") static SimpleFeatureCollection wrapGridCoverageReader(
            final GridCoverage2DReader gridCoverageReader, GeneralParameterValue[] params); static boolean isWrappedCoverageReader(SimpleFeatureType featureType); static java.awt.Polygon convertPolygon(
            final Polygon roiInput, MathTransform worldToGridTransform); static java.awt.Polygon convertPolygonToPointArray(
            final Polygon roiInput, MathTransform worldToGridTransform, List<Point2D> points); static Polygon getPolygon(final GeneralEnvelope env, final GeometryFactory gf); static double area(Point2D[] polyPoints); }
FeatureUtilities { public static java.awt.Polygon convertPolygonToPointArray( final Polygon roiInput, MathTransform worldToGridTransform, List<Point2D> points) throws TransformException { final boolean isIdentity = worldToGridTransform.isIdentity(); final double[] coords = new double[2]; final LineString exteriorRing = roiInput.getExteriorRing(); final CoordinateSequence exteriorRingCS = exteriorRing.getCoordinateSequence(); final int numCoords = exteriorRingCS.size(); final java.awt.Polygon retValue = new java.awt.Polygon(); for (int i = 0; i < numCoords; i++) { coords[0] = exteriorRingCS.getX(i); coords[1] = exteriorRingCS.getY(i); if (!isIdentity) worldToGridTransform.transform(coords, 0, coords, 0, 1); final int x = (int) Math.round(coords[0]); final int y = (int) Math.round(coords[1]); if (points != null) points.add(new Point2D.Double(coords[0], coords[1])); retValue.addPoint(x, y); } return retValue; } private  FeatureUtilities(); static Polygon getPolygon(final Rectangle2D rect, final int srid); @SuppressWarnings("unchecked") static SimpleFeatureCollection wrapGridCoverage(final GridCoverage2D coverage); static boolean isWrappedCoverage(SimpleFeatureType featureType); @SuppressWarnings("unchecked") static SimpleFeatureCollection wrapGridCoverageReader(
            final GridCoverage2DReader gridCoverageReader, GeneralParameterValue[] params); static boolean isWrappedCoverageReader(SimpleFeatureType featureType); static java.awt.Polygon convertPolygon(
            final Polygon roiInput, MathTransform worldToGridTransform); static java.awt.Polygon convertPolygonToPointArray(
            final Polygon roiInput, MathTransform worldToGridTransform, List<Point2D> points); static Polygon getPolygon(final GeneralEnvelope env, final GeometryFactory gf); static double area(Point2D[] polyPoints); static final FilterFactory2 DEFAULT_FILTER_FACTORY; static final PropertyName GRID_PROPERTY_NAME; static final PropertyName PARAMS_PROPERTY_NAME; }