コード例 #1
0
  @Override
  public Location addLocation(Long companyId, String name, Double coordX, Double coordY)
      throws Exception {
    try {
      Company company = companyDAO.findByPrimaryKey(companyId);
      if (company == null) {
        throw new Exception("Company doesn't exists");
      }

      Location location = new Location();
      location.setName(name);
      //			GeometryFactory geometryFactory = new GeometryFactory(new
      // PrecisionModel(PrecisionModel.FIXED), 4326);
      //			System.out.print("GeometryFactory");
      //			Geometry geom = (Geometry) geometryFactory.createPoint(new Coordinate(coordX, coordY));
      //			System.out.print("createPoint");
      //			location.setGeom(geom);
      //			System.out.print("setGeom");
      //			location.setCompany(company);
      //			System.out.print("setCompany");

      // First interpret the WKT string to a point
      WKTReader fromText = new WKTReader();
      Geometry geom = null;
      try {
        geom = fromText.read("POINT(10 5)");
      } catch (ParseException e) {
        throw new RuntimeException(
            "Not a WKT string:" + "SRID=4326;POINT(-56.2564083434446 -34.8982159791812)");
      }
      if (!geom.getGeometryType().equals("Point")) {
        throw new RuntimeException("Geometry must be a point. Got a " + geom.getGeometryType());
      }
      System.out.print("createPoint");
      location.setGeom((Point) geom);
      System.out.print("setGeom");
      location.setCompany(company);
      System.out.print("setCompany");

      company.getLocations().put(location.getName(), location);
      System.out.print("put");
      company = companyDAO.update(company);
      System.out.print("update");

      return company.getLocations().get(location.getName());
    } catch (Exception exc) {
      throw exc;
    }
  }
コード例 #2
0
ファイル: ST_PolyFromText.java プロジェクト: SPalominos/h2gis
 /**
  * @param wKT WellKnown text value
  * @param srid Valid SRID
  * @return Geometry
  * @throws SQLException Invalid argument or the geometry type is wrong.
  */
 public static Geometry toGeometry(String wKT, int srid) throws SQLException {
   Geometry geometry = ST_GeomFromText.toGeometry(wKT, srid);
   if (!geometry.getGeometryType().equalsIgnoreCase("POLYGON")) {
     throw new SQLException("The provided WKT Geometry is not a POLYGON.");
   }
   return geometry;
 }
コード例 #3
0
 public Geobuf.Data.Geometry geomToGeobuf(Geometry geometry) {
   if (geometry instanceof Point) return pointToGeobuf((Point) geometry);
   else if (geometry instanceof Polygon) return polyToGeobuf((Polygon) geometry);
   else if (geometry instanceof MultiPolygon) return multiPolyToGeobuf((MultiPolygon) geometry);
   else
     throw new UnsupportedOperationException(
         "Unsupported geometry type " + geometry.getGeometryType());
 }
コード例 #4
0
 @Override
 public void setValue(Geometry value) {
   if (value instanceof Polygon) {
     setValue((Polygon) value);
   } else {
     throw new IllegalArgumentException(
         "Cannot set this PolygonValue to a Geometry of type: " + value.getGeometryType());
   }
 }
コード例 #5
0
ファイル: ST_GeomUnion.java プロジェクト: JimmyFarcy/orbisgis
 private void addGeometry(Geometry geom) {
   if (geom.getGeometryType().equals("GeometryCollection")) {
     for (int i = 0; i < geom.getNumGeometries(); i++) {
       addGeometry(geom.getGeometryN(i));
     }
   } else {
     toUnite.add(geom);
   }
 }
コード例 #6
0
ファイル: TestListPanel.java プロジェクト: oschrenk/jts
 private String geometrySignature(Geometry geom) {
   if (geom == null) return "";
   String sig = geom.getGeometryType();
   if (geom instanceof GeometryCollection) {
     sig += "[" + geom.getNumGeometries() + "]";
   } else {
     sig += "(" + geom.getNumPoints() + ")";
   }
   return sig;
 }
コード例 #7
0
ファイル: ConvexHull.java プロジェクト: Redrazors/GameFrame
 public static KPolygon calcConvexHullPolygon(ArrayList<KPoint> array) {
   Coordinate[] coordinateArray = new Coordinate[array.size()];
   for (int i = 0; i < array.size(); i++) {
     KPoint p = array.get(i);
     coordinateArray[i] = new Coordinate(p.x, p.y);
   }
   com.vividsolutions.jts.algorithm.ConvexHull convexHull =
       new com.vividsolutions.jts.algorithm.ConvexHull(coordinateArray, new GeometryFactory());
   Geometry geometry = convexHull.getConvexHull();
   if (geometry.getGeometryType() == "Polygon") {
     Polygon jtsPolygon = (Polygon) geometry;
     PolygonConverter polygonConverter = new PolygonConverter();
     KPolygon convexHullKPolygon = polygonConverter.makeKPolygonFromExterior(jtsPolygon);
     return convexHullKPolygon;
   } else {
     System.out.println(": geometry.getGeometryType() == " + geometry.getGeometryType());
     throw new RuntimeException("Unknown JTS geometry type: " + geometry.getGeometryType());
   }
 }
コード例 #8
0
ファイル: Map.java プロジェクト: SOLA-SAMOA/clients
 /**
  * Adds the specified feature to the selection layer.
  *
  * @param id The identifier for the feature
  * @param geom The geometry of the feature.
  */
 public void selectFeature(String id, Geometry geom) {
   if (geom != null) {
     ExtendedLayerGraphics selectionLayer =
         (ExtendedLayerGraphics) getSolaLayers().get(SELECTION_LAYER_NAME);
     if (selectionLayer != null) {
       java.util.HashMap<String, Object> fieldValues = new java.util.HashMap<String, Object>();
       fieldValues.put(LAYER_FIELD_GEOMETRY_TYPE, geom.getGeometryType());
       selectionLayer.addFeature(id, geom, fieldValues, false);
     }
   }
 }
コード例 #9
0
 public boolean acceptGeometry(Geometry geom) {
   if (geom.getGeometryType().equals("GeometryCollection")) {
     for (int i = 0; i < geom.getNumGeometries(); i++) {
       if (acceptGeometry(geom.getGeometryN(i))) {
         return true;
       }
     }
     return false;
   } else {
     return willDrawSimpleGeometry(geom);
   }
 }
コード例 #10
0
 @Override
 public void filter(Geometry gmtr) {
   if (MultiPolygon.class.isAssignableFrom(binding)) {
     if (gmtr.getArea() != 0.0d && gmtr.getGeometryType().equals("Polygon")) {
       collection.add(gmtr);
     }
   }
   if (MultiLineString.class.isAssignableFrom(binding)) {
     if (gmtr.getLength() != 0.0d && gmtr.getGeometryType().equals("LineString")) {
       collection.add(gmtr);
     }
   }
   if (MultiPoint.class.isAssignableFrom(binding)) {
     if (gmtr.getNumGeometries() > 0 && gmtr.getGeometryType().equals("Point")) {
       collection.add(gmtr);
     }
   }
   if (Point.class.isAssignableFrom(binding)) {
     if (gmtr.getGeometryType().equals("Point")) {
       collection.add(gmtr);
     }
   }
 }
コード例 #11
0
 protected static Geometry transformGeometry(CoordinateTransform ct, Geometry geom)
     throws Exception {
   if (geom instanceof Polygon) {
     return transformPolygon(ct, (Polygon) geom);
   } else if (geom instanceof Point) {
     return transformPoint(ct, (Point) geom);
   } else if (geom instanceof LinearRing) {
     return transformLinearRing(ct, (LinearRing) geom);
   } else if (geom instanceof LineString) {
     return transformLineString(ct, (LineString) geom);
   } else if (geom instanceof MultiPolygon) {
     return transformMultiPolygon(ct, (MultiPolygon) geom);
   } else if (geom instanceof MultiPoint) {
     return transformMultiPoint(ct, (MultiPoint) geom);
   } else if (geom instanceof MultiLineString) {
     return transformMultiLineString(ct, (MultiLineString) geom);
   } else if (geom instanceof GeometryCollection) {
     return transformGeometryCollection(ct, (GeometryCollection) geom);
   } else {
     throw new Exception(Messages.gs(Messages.TEIID.TEIID31164, geom.getGeometryType()));
   }
 }
コード例 #12
0
ファイル: DecodeRadial.java プロジェクト: zsumore/cinrad
  @Override
  public void decodeData(boolean autoClosed)
      throws DecodeException, IOException, TransformException {
    super.decodeData(autoClosed);

    polyMultimap = ArrayListMultimap.create();

    radialDataBlock = new RadialDataBlock();
    radialDataBlock.builder(this.decodeCinradXHeader.getRandomAccessFile(), -1);

    if (autoClosed) {
      this.decodeCinradXHeader.getRandomAccessFile().close();
    }

    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setCRS(crs);
    builder.setName("Cinrad-X Radial Data");
    builder.add("geom", Geometry.class);
    builder.add("colorIndex", Float.class);
    builder.add("value", Float.class);
    schema = builder.buildFeatureType();

    // Reset index counter
    geoIndex = 0;

    if (getPlaneFeatures() == null) {
      planeFeatures = new DefaultFeatureCollection();
    }
    planeFeatures.clear();

    double minA = filter.getMinAzimuth();
    double maxA = filter.getMaxAzimuth();

    if (maxA - minA < 360.0) {
      while (minA >= 360.0) {
        minA -= 360.0;
        maxA -= 360.0;
      }
    }

    for (RadialData data : radialDataBlock.getRadialDatas()) {

      if (testInAzimuthRange(data, minA, maxA)) {
        double startAngle = data.getStartAngle();
        double endAngle = startAngle + data.getAngleWidth();

        // double angle1 = 90.0 - startAngle;
        // double angle2 = 90.0 - endAngle;

        if (startAngle < 0) {
          startAngle += 360;
        }
        if (endAngle < 0) {
          endAngle += 360;
        }

        // Add .00000001 to any 0, 90, 180, 270, 360 values to prevent
        // sin
        // or cos error
        if (startAngle == 0.0
            || startAngle == 90.0
            || startAngle == 180.0
            || startAngle == 270.0
            || startAngle == 360.0) {
          startAngle += 0.00001;
        }
        if (endAngle == 0.0
            || endAngle == 90.0
            || endAngle == 180.0
            || endAngle == 270.0
            || endAngle == 360.0) {
          endAngle += 0.00001;
        }

        startAngle = Math.toRadians(startAngle);
        endAngle = Math.toRadians(endAngle);

        int startRange = data.getRadialHeader().getStartRange();

        int key;
        float value;

        for (Map.Entry<Integer, Float> entry : data.getDataValueArray().entrySet()) {

          value = entry.getValue();
          if (testValueRange(value)) {
            key = entry.getKey();

            // double[] geoXY;
            double[] albX = new double[4];

            double[] albY = new double[4];

            int length1 = startRange + key * data.getRadialHeader().getResolution();
            albX[0] = length1 * Math.sin(startAngle);
            albY[0] = length1 * Math.cos(startAngle);
            albX[1] = length1 * Math.sin(endAngle);
            albY[1] = length1 * Math.cos(endAngle);

            int length2 = length1 + data.getRadialHeader().getResolution();
            albX[2] = length2 * Math.sin(endAngle);
            albY[2] = length2 * Math.cos(endAngle);
            albX[3] = length2 * Math.sin(startAngle);
            albY[3] = length2 * Math.cos(startAngle);

            Coordinate[] cArray = new Coordinate[5];
            // Add the first point
            double[] srcPts0 = {albX[0], albY[0]};
            double[] dstPts0 = new double[2];

            cinradTransform.transform(srcPts0, 0, dstPts0, 0, 1);
            cArray[0] = new Coordinate(dstPts0[0], dstPts0[1]);
            for (int nr = 1; nr < albX.length; nr++) {
              double[] srcPts = {albX[nr], albY[nr]};
              double[] dstPts = new double[2];

              cinradTransform.transform(srcPts, 0, dstPts, 0, 1);

              cArray[nr] = new Coordinate(dstPts[0], dstPts[1]);
            }

            // Add the first point again to close polygon
            cArray[4] = new Coordinate(dstPts0[0], dstPts0[1]);

            LinearRing lr = geoFactory.createLinearRing(cArray);
            Polygon poly = JTSUtilities.makeGoodShapePolygon(geoFactory.createPolygon(lr, null));

            // System.out.println("value:" + entry.getValue());

            if (configuration.getBoolean(COLOR_MODE, true)) {

              polyMultimap.put(CinradXUtils.getRadialColorIndex(entry.getValue()) * 1.0f, poly);
            } else {
              polyMultimap.put(entry.getValue(), poly);
            }
          }
        }
      }
    }

    Set<Float> valueSet = polyMultimap.keySet();
    // System.out.println(valueSet.size());
    if (valueSet.size() > 0) {
      for (Float v : valueSet) {

        Float color = new Float(v);

        Float value = color;
        if (configuration.getBoolean(COLOR_MODE, true)) {
          value = color * 5;
        }

        if (configuration.getBoolean(REDUCE_POLYGONS, true)) {
          logger.debug("REDUCING POLYGONS!");

          if (polyMultimap.get(v).size() > 0) {
            Polygon[] polyArray = new Polygon[polyMultimap.get(v).size()];

            GeometryCollection polyCollection =
                geoFactory.createGeometryCollection(polyMultimap.get(v).toArray(polyArray));

            Geometry union = polyCollection.buffer(geometryBuffer);

            union = TopologyPreservingSimplifier.simplify(union, geometrySimplify);

            logger.debug("Geometry Type:" + union.getGeometryType());

            // polyMultimap.get(v).clear();

            if (union.getGeometryType().equalsIgnoreCase("MultiPolygon")) {

              // logger.debug(union.toString());
              if (configuration.getBoolean(MULTIPOLYGON_MODE, true)) {
                SimpleFeature feature =
                    SimpleFeatureBuilder.build(
                        schema,
                        new Object[] {union, color, value},
                        new Integer(geoIndex++).toString());

                planeFeatures.add(feature);
              } else {

                MultiPolygon multiPolygon = (MultiPolygon) union;
                for (int j = 0; j < multiPolygon.getNumGeometries(); j++) {

                  // create the feature
                  SimpleFeature feature =
                      SimpleFeatureBuilder.build(
                          schema,
                          new Object[] {(Geometry) multiPolygon.getGeometryN(j), color, value},
                          new Integer(geoIndex++).toString());

                  planeFeatures.add(feature);

                  // logger.debug(feature.toString());

                }
              }

            } else if (union.getGeometryType().equalsIgnoreCase("Polygon")) {
              if (configuration.getBoolean(MULTIPOLYGON_MODE, true)) {
                // create the feature
                Polygon[] pa = {(Polygon) union};
                SimpleFeature feature =
                    SimpleFeatureBuilder.build(
                        schema,
                        new Object[] {(Geometry) new MultiPolygon(pa, geoFactory), color, value},
                        new Integer(geoIndex++).toString());

                planeFeatures.add(feature);

              } else {

                // create the feature
                SimpleFeature feature =
                    SimpleFeatureBuilder.build(
                        schema,
                        new Object[] {(Geometry) union, color, value},
                        new Integer(geoIndex++).toString());

                planeFeatures.add(feature);
              }

              // logger.debug(feature.toString());
            }
          }

        } else {

          for (Polygon poly : polyMultimap.get(v)) {

            SimpleFeature feature =
                SimpleFeatureBuilder.build(
                    schema, new Object[] {poly, color, value}, new Integer(geoIndex++).toString());

            planeFeatures.add(feature);

            // logger.debug(feature.toString());
          }
        }
      }
    }
  }
コード例 #13
0
 /**
  * Construct a geometry from the WKT representation of a geometry
  *
  * @param geom the constructor for the geometry.
  */
 public String db2Geom(Geometry geom) {
   String geomType = geom.getGeometryType();
   String g1 = geom.toText();
   String g2 = "db2gse.ST_" + geomType + "('" + g1 + "'," + getSRID() + ")";
   return g2;
 }
コード例 #14
0
 public UnsupportedGeometryTypeException(Geometry geometry) {
   super("Unsupported geometry type: " + (geometry == null ? "null" : geometry.getGeometryType()));
 }