public static void createGeom(List<Node> nodes) {
    StringBuilder wkt = new StringBuilder();
    for (Node node : nodes) wkt.append(node.lng + " " + node.lat + ", ");
    wkt.delete(wkt.length() - 2, wkt.length());

    wkt.insert(0, "POLYGON((");
    wkt.append("))");

    WKTReader wktreader = new WKTReader();
    Geometry geom = null;
    try {
      geom = wktreader.read(wkt.toString());
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    Polygon pol = (Polygon) geom;

    if (!pol.isValid()) {
      Geometry repaired = pol.buffer(0.0D);
      log.info("Invalid polygon detected. Is fixed? " + repaired.isValid());
      wkt = new StringBuilder(repaired.toText());
    }

    try {
      System.out.println(pol.contains(wktreader.read("POINT(82 25)")));
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Beispiel #2
0
 @Override
 public void modelChanged(Object element, String event) {
   if (element instanceof IDataContent) {
     try {
       IDataContent datacontent = (IDataContent) element;
       if (event == com.metaaps.eoclipse.common.Model.ADDED) {
         addDataLayer(datacontent);
       } else if (event == com.metaaps.eoclipse.common.Model.REMOVED) {
         removeDataLayer(datacontent);
       }
     } catch (ParseException e) {
       Util.errorMessage("Could not remove data layer.");
       e.printStackTrace();
     }
   }
 }
Beispiel #3
0
 private void renderLayers() {
   if ((m_datasets != null) && (canvas != null)) {
     // scan datasets for all data
     for (Object obj : m_datasets.getChildren()) {
       if (obj instanceof IDataContent) {
         IDataContent datacontent = (IDataContent) obj;
         try {
           addDataLayer(datacontent);
         } catch (ParseException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         }
       }
     }
   }
 }
 private double calculateArea(StringBuilder builder) {
   WKTReader reader = new WKTReader(geometryFactory);
   builder.append(this.firstLat).append(" ").append(this.firstLong);
   builder.append("))");
   try {
     System.out.println("generate polygon");
     Polygon polygon = (Polygon) reader.read("POLYGON ((" + builder.toString());
     double polygonArea = polygon.getArea();
     System.out.println("Area: " + polygonArea);
     return polygonArea;
   } catch (ParseException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return 0;
 }
Beispiel #5
0
  public Map<String, Geometry> readShapeFile(String filename, String attrString) {

    Map<String, Geometry> shapeMap = new HashMap<String, Geometry>();

    for (SimpleFeature ft : ShapeFileReader.getAllFeatures(filename)) {

      GeometryFactory geometryFactory = new GeometryFactory();
      WKTReader wktReader = new WKTReader(geometryFactory);
      Geometry geometry;

      try {
        geometry = wktReader.read((ft.getAttribute("the_geom")).toString());
        shapeMap.put(ft.getAttribute(attrString).toString(), geometry);

      } catch (ParseException e) {
        e.printStackTrace();
      }
    }
    return shapeMap;
  }
Beispiel #6
0
  public Map<String, Geometry> readShapeFile(String filename, String attrString) {
    // attrString: Für Brandenburg: Nr
    // für OSM: osm_id

    Map<String, Geometry> shapeMap = new HashMap<String, Geometry>();

    for (SimpleFeature ft : ShapeFileReader.getAllFeatures(filename)) {

      GeometryFactory geometryFactory = new GeometryFactory();
      WKTReader wktReader = new WKTReader(geometryFactory);
      Geometry geometry;

      try {
        geometry = wktReader.read((ft.getAttribute("the_geom")).toString());
        shapeMap.put(ft.getAttribute(attrString).toString(), geometry);

      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return shapeMap;
  }