示例#1
0
  private static void _testRing1(GeometryBuilder builder) {

    GeometryFactoryImpl tCoordFactory = (GeometryFactoryImpl) builder.getGeometryFactory();
    PrimitiveFactoryImpl tPrimFactory = (PrimitiveFactoryImpl) builder.getPrimitiveFactory();

    /* Defining Positions for LineStrings */
    ArrayList<Position> line1 = new ArrayList<Position>();
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {50, 20})));
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {30, 30})));
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {20, 50})));
    line1.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {20, 70})));

    ArrayList<Position> line2 = new ArrayList<Position>();
    line2.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {20, 70})));
    line2.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {40, 80})));
    line2.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {70, 80})));

    ArrayList<Position> line3 = new ArrayList<Position>();
    line3.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {70, 80})));
    line3.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {90, 70})));
    line3.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {100, 60})));
    line3.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {100, 40})));

    ArrayList<Position> line4 = new ArrayList<Position>();
    line4.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {100, 40})));
    line4.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {80, 30})));
    line4.add(new PositionImpl(tCoordFactory.createDirectPosition(new double[] {50, 20})));

    /* Setting up Array of these LineStrings */
    ArrayList<CurveSegment> tLineList1 = new ArrayList<CurveSegment>();
    tLineList1.add(tCoordFactory.createLineString(line1));
    tLineList1.add(tCoordFactory.createLineString(line2));

    ArrayList<CurveSegment> tLineList2 = new ArrayList<CurveSegment>();
    tLineList2.add(tCoordFactory.createLineString(line3));
    tLineList2.add(tCoordFactory.createLineString(line4));

    /* Build Curve */
    CurveImpl curve1 = tPrimFactory.createCurve(tLineList1);
    CurveImpl curve2 = tPrimFactory.createCurve(tLineList2);

    /* Build Ring */
    ArrayList<OrientableCurve> curveList = new ArrayList<OrientableCurve>();
    curveList.add(curve1);
    curveList.add(curve2);

    Ring ring1 = tPrimFactory.createRing(curveList);

    System.out.println(ring1);

    System.out.println(ring1.getEnvelope());

    PaintGMObject.paint(curve1);
  }
  public void write(Parcel parcel) {
    System.out.println(parcel);
    /*
     * We create a FeatureCollection into which we will put each Feature created from a record
     * in the input csv data file
     */
    DefaultFeatureCollection collection = new DefaultFeatureCollection("internal", TYPE);

    /*
     * GeometryFactory will be used to create the geometry attribute of each feature (a Point
     * object for the location)
     */
    //		GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);

    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(TYPE);
    builder.add(parcel.getCadastralNumber());
    builder.add(parcel.getState());
    builder.add(parcel.getDateCreated());
    builder.add(parcel.getArea());
    builder.add(parcel.getAreaUnit());
    builder.add(parcel.getName());
    builder.add(parcel.getLocationInBounds());
    Address address = parcel.getAddress();
    builder.add(address.getOkato());
    builder.add(address.getKladr());
    builder.add(address.getRegion());
    builder.add(address.getDistrictName());
    builder.add(address.getDistrictType());
    builder.add(address.getCityName());
    builder.add(address.getCityType());
    builder.add(address.getLocalityName());
    builder.add(address.getLocalityType());
    builder.add(address.getStreetName());
    builder.add(address.getStreetType());
    builder.add(address.getLevel1Value());
    builder.add(address.getNote());
    builder.add(parcel.getCategory());
    builder.add(parcel.getUtilization());
    builder.add(parcel.getUtilizationByDoc());
    builder.add(parcel.getCadastralCost());
    builder.add(parcel.getCadastralUnit());

    if (parcel.getEntitySpatial() != null
        && parcel.getEntitySpatial().getSpatialElements() != null
        && parcel.getEntitySpatial().getSpatialElements().size() > 0) {
      //			GeometryFactory geometryFactory = new GeometryFactory();
      //			Hints hints = new Hints(Hints.CRS, DefaultGeographicCRS.WGS84);
      //			PrimitiveFactory primitiveFactory = GeometryFactoryFinder.getPrimitiveFactory(hints);

      GeometryBuilder geometryBuilder = new GeometryBuilder(crs);
      PointArray points = null;
      //			List<Point> points = new ArrayList<>();
      for (SpatialElement spatialElement : parcel.getEntitySpatial().getSpatialElements()) {
        for (SpelementUnit spelementUnit : spatialElement.getSpelementUnits()) {
          for (Ordinate ordinate : spelementUnit.getOrdinates()) {
            double longitude = ordinate.getX();
            double latitude = ordinate.getY();
            int number = ordinate.getOrdNmb();
            /* Longitude (= x coord) first ! */
            Point point = geometryBuilder.createPoint(new double[] {longitude, latitude});
            //						Point point = primitiveFactory.createPoint(new double[]{longitude, latitude});
            points.add(number, point);
          }
          SimpleFeature feature = builder.buildFeature(null);
          collection.add(feature);
        }
      }
      builder.add(geometryBuilder.createPolygon(geometryBuilder.createSurfaceBoundary(points)));
      //			geometryFactory.createMultiPolygon(new Polygon[]{});
    }

    /*
     * Write the features to the shapefile
     */
    Transaction transaction = new DefaultTransaction("create");

    String typeName = null;
    try {
      typeName = newDataStore.getTypeNames()[0];
    } catch (IOException e) {
      e.printStackTrace();
    }
    SimpleFeatureSource featureSource = null;
    try {
      featureSource = newDataStore.getFeatureSource(typeName);
    } catch (IOException e) {
      e.printStackTrace();
    }

    if (featureSource instanceof SimpleFeatureStore) {
      SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;

      featureStore.setTransaction(transaction);
      try {
        featureStore.addFeatures(collection);
        transaction.commit();

      } catch (Exception problem) {
        problem.printStackTrace();
        try {
          transaction.rollback();
        } catch (IOException e) {
          e.printStackTrace();
        }

      } finally {
        try {
          transaction.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    } else {
      System.out.println(typeName + " does not support read/write access");
    }
  }