當前位置: 首頁>>代碼示例>>Java>>正文


Java Polygon類代碼示例

本文整理匯總了Java中com.vividsolutions.jts.geom.Polygon的典型用法代碼示例。如果您正苦於以下問題:Java Polygon類的具體用法?Java Polygon怎麽用?Java Polygon使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Polygon類屬於com.vividsolutions.jts.geom包,在下文中一共展示了Polygon類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: flatten

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
/** */
public static Geometry flatten (GeometryCollection gc) {
    final List<Point> points = new LinkedList<Point>();
    final List<LineString> lines = new LinkedList<LineString>();
    final List<Polygon> polygons = new LinkedList<Polygon>();
    gc.apply(new GeometryFilter() {
            public void filter (Geometry geom) {
                if (geom instanceof Point) {
                    points.add((Point)geom);
                } else if (geom instanceof LineString) {
                    lines.add((LineString)geom);
                } else if (geom instanceof Polygon) {
                    polygons.add((Polygon)geom);
                }
            }
        });
    if (!polygons.isEmpty()) {
        return gc.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons));
    } else if (!lines.isEmpty()) {
        return gc.getFactory().createMultiLineString(GeometryFactory.toLineStringArray(lines));
    } else {
        return gc.getFactory().createMultiPoint(GeometryFactory.toPointArray(points));
    }
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:25,代碼來源:JTSUtil.java

示例2: getShape

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
public Area getShape() {
    Area maskArea = new Area();
    Rectangle rect = new Rectangle(0, 0, reader.getWidth(), reader.getHeight());
    GeometryFactory gf = new GeometryFactory();
    Coordinate[] coords = new Coordinate[]{
        new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
        new Coordinate((int) rect.getMaxX(), (int) rect.getMinY()),
        new Coordinate((int) rect.getMaxX(), (int) rect.getMaxY()),
        new Coordinate((int) rect.getMinX(), (int) rect.getMaxY()),
        new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
    };
    Polygon geom = gf.createPolygon(gf.createLinearRing(coords), null);
    for (Geometry p : glayer.getGeometries()) {
        if (p.intersects(geom)) {
            int[] xPoints = new int[p.getNumPoints()];
            int[] yPoints = new int[p.getNumPoints()];
            int i = 0;
            for (Coordinate c : p.getCoordinates()) {
                xPoints[i] = (int) (c.x);
                yPoints[i++] = (int) (c.y);
            }
            maskArea.add(new Area(new java.awt.Polygon(xPoints, yPoints, p.getNumPoints())));
        }
    }
    return maskArea;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:27,代碼來源:InterpolatedVectorLayer.java

示例3: createPolygon

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
/**
 *
 * @param xs
 * @return
 * @throws ParseException
 */
public static Polygon createPolygon(double[]...xs) throws ParseException{
	StringBuilder builder =new StringBuilder("POLYGON((");

	for(int i=0;i<xs.length;i++){
		double x[]=xs[i];
		if(i<(xs.length-1))
			builder=builder.append(x[0]).append(" ").append(x[1]).append(",");
		else
			builder=builder.append(x[0]).append(" ").append(x[1]).append("))");
	}
	Polygon imageP = (Polygon) new WKTReader().read(builder.toString());
	/*Coordinate[]cs=new Coordinate[xs.length];
	for(int i=0;i<xs.length;i++){
		cs[i]=new Coordinate(xs[i][0],xs[i][1]);
	}
	GeometryFactory factor=new GeometryFactory();
	Polygon imageP=factor.createPolygon(cs);*/

	return imageP;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:27,代碼來源:PolygonOp.java

示例4: rasterize

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
/**
 * rasterize the mask clipped with the Rectangle scaled back to full size with an offset onto a BufferedImage
 */
public BufferedImage rasterize(Rectangle rect, int offsetX, int offsetY, double scalingFactor) {

	// create the buffered image of the size of the Rectangle
    BufferedImage image = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_BYTE_BINARY);
    GeometryFactory gf = new GeometryFactory();

    // define the clipping region in full scale
    Coordinate[] coords = new Coordinate[]{
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMaxY() / scalingFactor))),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor)), (int) (((double) rect.getMinY() / scalingFactor))),};

    Polygon geom = gf.createPolygon(gf.createLinearRing(coords));

    Graphics g2d = image.getGraphics();

    g2d.setColor(Color.white);
    for (Geometry p : maskGeometries) {
    	/*if(p instanceof MultiPolygon){
    		p=p.getBoundary();
    	}*/
        if (p.intersects(geom)) {
            int[] xPoints = new int[p.getNumPoints()];//build array for x coordinates
            int[] yPoints = new int[p.getNumPoints()];//build array for y coordinates
            int i = 0;
            for (Coordinate c : p.getCoordinates()) {
                xPoints[i] = (int) ((c.x + offsetX ) * scalingFactor);
                yPoints[i] = (int) ((c.y + offsetY ) * scalingFactor);
                i++;
            }
            g2d.fillPolygon(xPoints, yPoints, i);
        }
    }
    g2d.dispose();
    return image;

}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:43,代碼來源:MaskGeometries.java

示例5: loadShapeFile

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
/**
 *
 * @param args
 */
private GeometryImage loadShapeFile(File file,String name){//String[] args) {
    GeometryImage gl=null;

    ImageLayer imgLayer=LayerManager.getIstanceManager().getCurrentImageLayer();
    if(imgLayer!=null){
    	try {
    		Polygon imageP=((SarImageReader)imgLayer.getImageReader()).getBbox(PlatformConfiguration.getConfigurationInstance().getLandMaskMargin(0));
    		long start=System.currentTimeMillis();
             gl = SimpleShapefile.createIntersectedLayer(file,imageP,((SarImageReader)imgLayer.getImageReader()).getGeoTransform());
            long end=System.currentTimeMillis();
            System.out.println("Shapefile loaded in:"+(end-start));
            // if 5 args, set a specific name
            if (name!=null&&!name.equals("")) {
                if (gl != null) {
                    gl.setName(name);
                }
            }
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }
    return gl;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:28,代碼來源:AddVectorConsoleAction.java

示例6: compare

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
public int compare (Polygon p1, Polygon p2) {
    if (p1.contains(p2)) {
        return(1);
    } else if (p2.contains(p1)) {
        return(-1);
    } else {
        return(0);
    }
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:10,代碼來源:JTSUtil.java

示例7: repair

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
/**
 *
 * @param geom
 * @return
 */
public static Geometry repair (Geometry geom) {
    GeometryFactory factory = geom.getFactory();
    if (geom instanceof MultiPolygon) {
        MultiPolygon mp = (MultiPolygon)geom;
        Polygon[] polys = new Polygon[mp.getNumGeometries()];
        for (int i = 0; i < mp.getNumGeometries(); i += 1) {
            polys[i] = repair((Polygon)mp.getGeometryN(i));
        }
        return factory.createMultiPolygon(polys);
    } else if (geom instanceof Polygon) {
        return repair((Polygon)geom);
    } else if (geom.getGeometryType().equals("GeometryCollection")) {
        GeometryCollection gc = (GeometryCollection)geom;
        Geometry[] geoms = new Geometry[gc.getNumGeometries()];
        for (int i = 0; i < gc.getNumGeometries(); i += 1) {
            geoms[i] = repair(gc.getGeometryN(i));
        }
        Thread.dumpStack();
        return factory.createGeometryCollection(geoms);
    } else {
        return(geom);
    }
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:29,代碼來源:JTSUtil.java

示例8: mouseClicked

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
/**
 *
 * @param imagePosition
 * @param context
 */
public void mouseClicked(java.awt.Point imagePosition, OpenGLContext context) {
	if(isEditable()){
     this.selectedGeometry = null;
     GeometryFactory gf = new GeometryFactory();
     com.vividsolutions.jts.geom.Point p = gf.createPoint(new Coordinate(imagePosition.x, imagePosition.y));
     for (Geometry temp : glayer.getGeometries()) {
     	if(temp instanceof Polygon){
      	Coordinate[] c=DistanceOp.nearestPoints(temp, p);
      	com.vividsolutions.jts.geom.Point nearest=gf.createPoint(c[0]);
          if (nearest.isWithinDistance(temp,5 * context.getZoom())) {
              this.selectedGeometry = temp;
              System.out.println(""+temp.getCoordinate().x+","+temp.getCoordinate().y);
              LayerPickedData.put(temp, glayer.getAttributes(temp));
              break;
          }
     	}
     }
	}
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:25,代碼來源:MaskVectorLayer.java

示例9: smooth

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
private static Geometry smooth(final Geometry geom, final double fit,
        final GeometryFactory factory, GeometrySmoother smoother) {

    switch (geom.getGeometryType().toUpperCase()) {
    case "POINT":
    case "MULTIPOINT":
        // For points, just return the input geometry
        return geom;

    case "LINESTRING":
        // This handles open and closed lines (LinearRings)
        return smoothLineString(factory, smoother, geom, fit);

    case "MULTILINESTRING":
        return smoothMultiLineString(factory, smoother, geom, fit);

    case "POLYGON":
        return smoother.smooth((Polygon) geom, fit);

    case "MULTIPOLYGON":
        return smoothMultiPolygon(factory, smoother, geom, fit);

    case "GEOMETRYCOLLECTION":
        return smoothGeometryCollection(factory, smoother, geom, fit);

    default:
        throw new UnsupportedOperationException("No smoothing method available for "
                + geom.getGeometryType());
    }
}
 
開發者ID:GIScience,項目名稱:openrouteservice,代碼行數:31,代碼來源:JTS.java

示例10: rasterize

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
public BufferedImage rasterize(BufferedImage image, int offsetX, int offsetY, double scalingFactor) {
    Rectangle rect = image.getRaster().getBounds();
    GeometryFactory gf = new GeometryFactory();
    Coordinate[] coords = new Coordinate[]{
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
        new Coordinate((int) (((double) rect.getMaxX() / scalingFactor) + offsetX), (int) (((double) rect.getMaxY() / scalingFactor) + offsetY)),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMaxY() / scalingFactor) + offsetY)),
        new Coordinate((int) (((double) rect.getMinX() / scalingFactor) + offsetX), (int) (((double) rect.getMinY() / scalingFactor) + offsetY)),
    };
    Polygon geom = gf.createPolygon(gf.createLinearRing(coords), null);
    Graphics g2d = image.getGraphics();
    g2d.setColor(Color.WHITE);
    for (Geometry p : glayer.getGeometries()) {
        if (p.intersects(geom)) {
            int[] xPoints = new int[p.getNumPoints()];
            int[] yPoints = new int[p.getNumPoints()];
            int i = 0;
            for (Coordinate c : p.getCoordinates()) {
                xPoints[i] = (int) ((c.x - offsetX) * scalingFactor);
                yPoints[i++] = (int) ((c.y - offsetY) * scalingFactor);
            }
            g2d.fillPolygon(xPoints, yPoints, p.getNumPoints());
        }
    }
    g2d.dispose();
    return image;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:29,代碼來源:InterpolatedVectorLayer.java

示例11: should_split_polygon_in_16

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
@Test
public void should_split_polygon_in_16() {
    Polygon polygon = polygon(
            new Coordinate(0.0, 0.0),
            new Coordinate(1.0, 0.0),
            new Coordinate(1.0, 1.0),
            new Coordinate(0.0, 1.0),
            new Coordinate(0.0, 0.0));

    List<Geometry> geoms = LargePolygonSplitter.split(polygon, 0.1);

    assertThat(geoms).extracting(Geometry::toString).hasSize(16).contains(
            "POLYGON ((0.25 0, 0 0, 0 0.25, 0.25 0.25, 0.25 0))",
            "POLYGON ((0 0.25, 0 0.5, 0.25 0.5, 0.25 0.25, 0 0.25))",
            "POLYGON ((0.25 0.5, 0.5 0.5, 0.5 0.25, 0.25 0.25, 0.25 0.5))");
}
 
開發者ID:Mappy,項目名稱:fpm,代碼行數:17,代碼來源:LargePolygonSplitterTest.java

示例12: checkSearchRadius

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
private static void checkSearchRadius(Geometry geom, double value) throws Exception
{
	if (geom instanceof Point)
	{
		if (LocationsServiceSettings.getMaximumSearchRadiusForPoints() > 0 && LocationsServiceSettings.getMaximumSearchRadiusForPoints() < value)
			throw new ParameterOutOfRangeException(LocationsErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, "radius", Double.toString(value), Double.toString(LocationsServiceSettings.getMaximumSearchRadiusForPoints()));
	}
	else if (geom instanceof LineString)
	{
		if (LocationsServiceSettings.getMaximumSearchRadiusForLinestrings() > 0 && LocationsServiceSettings.getMaximumSearchRadiusForLinestrings() < value)
			throw new ParameterOutOfRangeException(LocationsErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, "radius", Double.toString(value), Double.toString(LocationsServiceSettings.getMaximumSearchRadiusForLinestrings()));
	}
	else if (geom instanceof Polygon)
	{
		if (LocationsServiceSettings.getMaximumSearchRadiusForPolygons() > 0 && LocationsServiceSettings.getMaximumSearchRadiusForPolygons() < value)
			throw new ParameterOutOfRangeException(LocationsErrorCodes.PARAMETER_VALUE_EXCEEDS_MAXIMUM, "radius", Double.toString(value), Double.toString(LocationsServiceSettings.getMaximumSearchRadiusForPolygons()));
	}
}
 
開發者ID:GIScience,項目名稱:openrouteservice,代碼行數:19,代碼來源:JsonLocationsRequestParser.java

示例13: main

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
public static void main(String[] args) {
	ReedsSheppCarPlanner rsp = new ReedsSheppCarPlanner();
	Coordinate footprint1 = new Coordinate(-2.0,0.5);
	Coordinate footprint2 = new Coordinate(2.0,0.5);
	Coordinate footprint3 = new Coordinate(2.0,-0.5);
	Coordinate footprint4 = new Coordinate(-2.0,-0.5);
	rsp.setRadius(0.5);
	rsp.setFootprint(footprint1,footprint2,footprint3,footprint4);
	JTSDrawingPanel panel = JTSDrawingPanel.makeEmpty("debug");
	GeometryFactory gf = new GeometryFactory();
	Polygon footprint = gf.createPolygon(new Coordinate[] {footprint1,footprint2,footprint3,footprint4,footprint1});
	Polygon smoothedFootprint = gf.createPolygon(rsp.getCollisionCircleCenters());
	System.out.println("Smoothing went from " + footprint.getCoordinates().length + " to " + smoothedFootprint.getCoordinates().length + " points");
	panel.addGeometry("orig", footprint, true, true, true, "#00FF00");
	panel.addGeometry("smooth", smoothedFootprint, false, false, true, "#FF0000");
	for (int i = 0; i < smoothedFootprint.getCoordinates().length; i++) {
		double delta = 0.1;
		Coordinate p1 = new Coordinate(smoothedFootprint.getCoordinates()[i].x,smoothedFootprint.getCoordinates()[i].y);
		Coordinate p2 = new Coordinate(smoothedFootprint.getCoordinates()[i].x+delta,smoothedFootprint.getCoordinates()[i].y+delta);
		Coordinate p3 = new Coordinate(smoothedFootprint.getCoordinates()[i].x-delta,smoothedFootprint.getCoordinates()[i].y+delta);
		panel.addGeometry("_cp"+i, gf.createPolygon(new Coordinate[] {p1,p2,p3,p1}), false, false, false, "#000000");
	}
	

}
 
開發者ID:FedericoPecora,項目名稱:coordination_oru,代碼行數:26,代碼來源:TestReedsSheppCarPlannerSmoothGeometry.java

示例14: removeCollinearVertices

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
/**
 * Removes collinear vertices from the provided {@link Geometry}.
 * 
 * <p>
 * For the moment this implementation only accepts, {@link Polygon}, {@link LineString} and {@link MultiPolygon} It will throw an exception if the
 * geometry is not one of those types
 * 
 * @param g the instance of a {@link Geometry} to remove collinear vertices from.
 * @return a new instance of the provided {@link Geometry} without collinear vertices.
 */
public static Geometry removeCollinearVertices(final Geometry g) {
    if (g == null) {
        throw new NullPointerException("The provided Geometry is null");
    }
    if (g instanceof LineString) {
        return removeCollinearVertices((LineString) g);
    } else if (g instanceof Polygon) {
        return removeCollinearVertices((Polygon) g);
    } else if (g instanceof MultiPolygon) {
        MultiPolygon mp = (MultiPolygon) g;
        Polygon[] parts = new Polygon[mp.getNumGeometries()];
        for (int i = 0; i < mp.getNumGeometries(); i++) {
            Polygon part = (Polygon) mp.getGeometryN(i);
            part = removeCollinearVertices(part);
            parts[i] = part;
        }

        return g.getFactory().createMultiPolygon(parts);
    }

    throw new IllegalArgumentException(
            "This method can work on LineString, Polygon and Multipolygon: " + g.getClass());
}
 
開發者ID:GIScience,項目名稱:openrouteservice,代碼行數:34,代碼來源:JTS.java

示例15: mergePolygons

import com.vividsolutions.jts.geom.Polygon; //導入依賴的package包/類
/**
*
* @param polygons
* @return
*/
  public static List<Geometry> mergePolygons(List<Geometry> polygons) {
  	boolean done;
  	do {
  	done = true;
  	for (int i = 0; i < polygons.size(); i++) {
  		Geometry a = polygons.get(i);
  	    for (int j = i + 1; j < polygons.size();) {
  	        final Geometry b = polygons.get(j);
  	        if (a.intersects(b)) {

  	            polygons.set(i, (Polygon) a.union(b));
  	            a = polygons.get(i);
  	            polygons.remove(j);
  	            done = false;
  	        }
  	        else {
  	            j++;
  	        }
  	    }
  	}
  	} while (!done);

  	return polygons;
  }
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:30,代碼來源:PolygonOp.java


注:本文中的com.vividsolutions.jts.geom.Polygon類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。