@Test()
  public void testSonyDSCHXV5()
      throws IOException, CatalogTransformerException, UnsupportedQueryException,
          SourceUnavailableException, FederationException, ParseException {
    File file = new File(TEST_DATA_PATH + "Sony DSC-HX5V.jpg");
    FileInputStream fis = FileUtils.openInputStream(file);
    Metacard metacard = createTransformer().transform(fis);

    assertNotNull(metacard);

    assertNotNull(metacard.getCreatedDate());
    assertThat(metacard.getCreatedDate().getYear() + 1900, is(2010));
    assertThat(metacard.getCreatedDate().getMonth() + 1, is(7));
    assertThat(metacard.getCreatedDate().getDate(), is(14));
    assertThat(metacard.getCreatedDate().getHours(), is(11));
    assertThat(metacard.getCreatedDate().getMinutes(), is(00));
    assertThat(metacard.getCreatedDate().getSeconds(), is(23));

    assertNotNull(metacard.getModifiedDate());
    assertThat(metacard.getModifiedDate().getYear() + 1900, is(2010));
    assertThat(metacard.getModifiedDate().getMonth() + 1, is(7));
    assertThat(metacard.getModifiedDate().getDate(), is(14));
    assertThat(metacard.getModifiedDate().getHours(), is(11));
    assertThat(metacard.getModifiedDate().getMinutes(), is(00));
    assertThat(metacard.getModifiedDate().getSeconds(), is(23));

    WKTReader reader = new WKTReader();
    Geometry geometry = reader.read(metacard.getLocation());
    assertEquals(-104.303846389, geometry.getCoordinate().x, 0.00001);
    assertEquals(39.5698783333, geometry.getCoordinate().y, 0.00001);

    byte[] thumbnail = metacard.getThumbnail();
    assertNotNull(thumbnail);
    assertThat(thumbnail.length, is(11490));
  }
  @Test()
  public void testIPhone()
      throws IOException, CatalogTransformerException, UnsupportedQueryException,
          SourceUnavailableException, FederationException, ParseException {
    File file = new File(TEST_DATA_PATH + "Apple iPhone 4.jpg");
    FileInputStream fis = FileUtils.openInputStream(file);
    Metacard metacard = createTransformer().transform(fis);

    assertNotNull(metacard);

    assertNotNull(metacard.getCreatedDate());
    assertThat(metacard.getCreatedDate().getYear() + 1900, is(2011));
    assertThat(metacard.getCreatedDate().getMonth() + 1, is(1));
    assertThat(metacard.getCreatedDate().getDate(), is(13));
    assertThat(metacard.getCreatedDate().getHours(), is(14));
    assertThat(metacard.getCreatedDate().getMinutes(), is(33));
    assertThat(metacard.getCreatedDate().getSeconds(), is(39));

    assertEquals(metacard.getCreatedDate(), metacard.getModifiedDate());

    WKTReader reader = new WKTReader();
    Geometry geometry = reader.read(metacard.getLocation());
    assertEquals(12.488833, geometry.getCoordinate().x, 0.00001);
    assertEquals(41.853, geometry.getCoordinate().y, 0.00001);
  }
 private void readGoodCheckCoordinate(String wkt, double x, double y)
     throws IOException, ParseException {
   Geometry g = rdr.read(wkt);
   Coordinate pt = g.getCoordinate();
   assertEquals(pt.x, x, 0.0001);
   assertEquals(pt.y, y, 0.0001);
 }
  public void testVectorReprojector() throws Exception {

    SimpleFeatureCollection testFC = HMTestMaps.testFC;

    OmsVectorReprojector reprojector = new OmsVectorReprojector();
    reprojector.inVector = testFC;
    reprojector.pCode = "EPSG:4326";
    reprojector.pm = pm;
    reprojector.process();

    CoordinateReferenceSystem sourceCRS = HMTestMaps.crs;
    CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");

    MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);

    SimpleFeatureCollection outFC = reprojector.outVector;
    FeatureIterator<SimpleFeature> featureIterator = outFC.features();
    SimpleFeatureIterator originalFeatureIterator = testFC.features();
    while (featureIterator.hasNext()) {
      SimpleFeature feature = featureIterator.next();
      Geometry geometry = (Geometry) feature.getDefaultGeometry();
      Coordinate coordinate = geometry.getCoordinate();

      SimpleFeature originalFeature = originalFeatureIterator.next();
      Coordinate origCoord = ((Geometry) originalFeature.getDefaultGeometry()).getCoordinate();
      Coordinate reprojected = JTS.transform(origCoord, null, transform);

      assertEquals(reprojected.x, coordinate.x, delta);
      assertEquals(reprojected.y, coordinate.y, delta);
    }
    featureIterator.close();
  }
예제 #5
0
파일: Geo.java 프로젝트: runeengh/basex
  /**
   * Returns the z-coordinate value for point.
   *
   * @param node xml element containing gml object(s)
   * @return z double value
   * @throws QueryException query exception
   */
  @Deterministic
  public Dbl z(final ANode node) throws QueryException {
    final Geometry geo = geo(node, Q_GML_POINT);
    if (geo == null && checkGeo(node) != null)
      throw GeoErrors.geoType(node.qname().local(), "Line");

    return Dbl.get(geo.getCoordinate().z);
  }
예제 #6
0
  /** Test of parse method, of class GMLParser. */
  @Test
  public void testParse() throws Exception {
    System.out.println("GMLParser.parse");
    String serialisation =
        "<gml:Point srsName=\"EPSG:4326\"><gml:coordinates>6.0,4.0</gml:coordinates></gml:Point>";
    Map<String, Variable> variableMap = new HashMap<>();
    Variable var = new Variable("?x", RuleTriple.GML);
    var.setContent(Optional.of(serialisation));
    variableMap.put("?x", var);
    double longitude = 4.0;
    double latitude = 6.0;

    GMLParser parser = new GMLParser();

    System.out.println("    -- Testing with 4326");
    Geometry result = parser.parseGeometry(variableMap);
    assertEquals(latitude, result.getCoordinate().x, 0);
    assertEquals(longitude, result.getCoordinate().y, 0);
  }
  @Test()
  public void testPointGeo() throws IOException, CatalogTransformerException, Exception {
    AISInputTransformer transformer = createTransformer();

    Metacard metacard =
        transformer.transform(new ByteArrayInputStream(sampleNMEAString3().getBytes()));

    WKTReader reader = new WKTReader();

    Geometry geometry = reader.read(metacard.getLocation());

    assertEquals(
        geometry.getCoordinate().x + " doesn't equal " + "-19.046145",
        String.valueOf(geometry.getCoordinate().x),
        "-19.046145");

    assertEquals(
        geometry.getCoordinate().y + " doesn't equal " + "-18.227776666666667",
        String.valueOf(geometry.getCoordinate().y),
        "-18.227776666666667");
  }
예제 #8
0
  /**
   * Method used to draw a point on map.
   *
   * @param fill
   * @param stroke
   */
  public void drawPoints(Paint fill, Paint stroke) {
    ShapeWriter wr = new ShapeWriter(pointTransformer, style4Table.shape, style4Table.size);
    wr.setRemoveDuplicatePoints(true);
    wr.setDecimation(style4Table.decimationFactor);
    while (geometryIterator.hasNext()) {
      Geometry geom = geometryIterator.next();
      geom.getCoordinate();
      DrawableShape shape = wr.toShape(geom);

      if (fill != null) {
        shape.fill(canvas, fill);
      }
      if (stroke != null) {
        shape.draw(canvas, stroke);
      }
    }
  }
 /**
  * Get the geometry from featureOfInterest object.
  *
  * @param feature
  * @return geometry
  * @throws OwsExceptionReport
  */
 public Geometry createGeometry(final HasCoordinate coodinates) throws OwsExceptionReport {
   if (coodinates.isSetLongLat()) {
     int epsg = getStorageEPSG();
     if (coodinates.isSetSrid()) {
       epsg = coodinates.getSrid();
     }
     final String wktString =
         GeometryHandler.getInstance()
             .getWktString(coodinates.getLongitude(), coodinates.getLatitude(), epsg);
     final Geometry geom = JTSHelper.createGeometryFromWKT(wktString, epsg);
     if (coodinates.isSetAltitude()) {
       geom.getCoordinate().z = JavaHelper.asDouble(coodinates.getAltitude());
       if (geom.getSRID() == getStorage3DEPSG()) {
         geom.setSRID(getStorage3DEPSG());
       }
     }
     return geom;
   }
   return null;
 }
 private boolean inspectGeometry(Geometry g) {
   double d = g.getCoordinate().z;
   return !(Double.isNaN(d) || d == 0);
 }
예제 #11
0
  /**
   * Checks if the intersecting segment intersects with a hole in two points. In that case, the
   * segment might be adjusted following the orientation of the intersected hole.
   *
   * @param intersectingSegment this segment that could intersect with a hole
   * @param holeGeometries the polygon hole list
   */
  private LineString adjustSegmentToHoleDirection(
      final Geometry intersectingSegment, final Geometry holeGeometries) {

    LineString intersectedHole = intersectionHole(intersectingSegment, holeGeometries);

    if (intersectedHole == null) {
      return (LineString) intersectingSegment; // it does not require
      // adjust orientation
    }

    // Traverses the hole-segments until the second intersection with the
    // intersectingSegment is found
    // a ring will be created with those segments between first intersection
    // and second intersection.
    Coordinate secondIntersection = null;
    Coordinate firstIntersection = null;
    int j = -1;
    Coordinate[] holeCoords = intersectedHole.getCoordinates();
    List<Coordinate> ring = new LinkedList<Coordinate>();
    for (int i = 0; i < holeCoords.length - 1; i++) {

      Geometry intersection = intersectionWithSegment(holeCoords, i, intersectingSegment);
      if (intersection instanceof Point) {

        // store first and second coordinates
        if (firstIntersection == null) {

          firstIntersection = intersection.getCoordinate();
          ring.add(firstIntersection);
          ring.add(holeCoords[i + 1]);
          j = i + 1;
          break;
        }
        // Adds the rest of segments in the ring until found a second
        // intersection
      }
    }
    assert firstIntersection != null && j != -1;

    while (true) {
      Geometry intersection = intersectionWithSegment(holeCoords, j, intersectingSegment);

      if (intersection instanceof Point
          && !intersection.getCoordinate().equals2D(firstIntersection)) {
        secondIntersection = intersection.getCoordinate();
        ring.add(secondIntersection);
        // close the ring
        ring.add(firstIntersection);
        break;

      } else {
        ring.add(holeCoords[j + 1]);
      }
      j++;
    }

    assert secondIntersection != null;

    // Creates the adjusted line following this rules:
    // - if the ring is CW then the result line must be this: first
    // intersection coordinate--> second intersection coordinate.
    // - if the ring is CCW the the result line must be this: second
    // intersection coordinate --> first intersection coordinate.
    GeometryFactory factory = intersectingSegment.getFactory();
    LinearRing linearRing = factory.createLinearRing(ring.toArray(new Coordinate[ring.size()]));

    LineString adjustedSegment = null;
    if (isCW(linearRing)) {

      adjustedSegment = createAdjustedSegment(firstIntersection, secondIntersection, factory);

    } else {

      adjustedSegment = createAdjustedSegment(secondIntersection, firstIntersection, factory);
    }
    return adjustedSegment;
  }
  /**
   * Write SQL string to create tables in the test database based on the property files.
   *
   * @param propertyFiles Property files from app-schema-test suite.
   * @param parser The parser (WKT or an SC4O one for 3D tests)
   * @throws IllegalAttributeException
   * @throws NoSuchElementException
   * @throws IOException
   */
  private void createTables(Map<String, File> propertyFiles, String parser)
      throws IllegalAttributeException, NoSuchElementException, IOException {

    StringBuffer buf = new StringBuffer();
    StringBuffer spatialIndex = new StringBuffer();
    // drop table procedure I copied from Victor's Oracle_Data_ref_set.sql
    buf.append("CREATE OR REPLACE PROCEDURE DROP_TABLE_OR_VIEW(TabName in Varchar2) IS ")
        .append("temp number:=0;")
        .append(" tes VARCHAR2 (200) := TabName;")
        .append(" drp_stmt VARCHAR2 (200):=null;")
        .append("BEGIN select count(*) into temp from user_tables where TABLE_NAME = tes;")
        .append("if temp = 1 then drp_stmt := 'Drop Table '||tes;")
        .append("EXECUTE IMMEDIATE drp_stmt;")
        // drop views too
        .append("else select count(*) into temp from user_views where VIEW_NAME = tes;")
        .append("if temp = 1 then drp_stmt := 'Drop VIEW '||tes;")
        .append("EXECUTE IMMEDIATE drp_stmt;end if;end if;")
        .append("EXCEPTION WHEN OTHERS THEN ")
        .append(
            "raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);")
        .append("END DROP_TABLE_OR_VIEW;\n");

    for (String fileName : propertyFiles.keySet()) {
      File file = new File(propertyFiles.get(fileName), fileName);

      try (PropertyFeatureReader reader = new PropertyFeatureReader("test", file)) {
        SimpleFeatureType schema = reader.getFeatureType();
        String tableName = schema.getName().getLocalPart().toUpperCase();
        // drop table if exists
        buf.append("CALL DROP_TABLE_OR_VIEW('").append(tableName).append("')\n");
        // create the table
        buf.append("CREATE TABLE ").append(tableName).append("(");
        // + pkey
        int size = schema.getAttributeCount() + 1;
        String[] fieldNames = new String[size];
        List<String> createParams = new ArrayList<String>();
        int j = 0;
        String type;
        String field;
        int spatialIndexCounter = 0;
        for (PropertyDescriptor desc : schema.getDescriptors()) {
          field = desc.getName().toString().toUpperCase();
          fieldNames[j] = field;
          if (desc instanceof GeometryDescriptor) {
            type = "SDO_GEOMETRY";
            // Update spatial index
            int srid = getSrid(((GeometryType) desc.getType()));

            spatialIndex
                .append("DELETE FROM user_sdo_geom_metadata WHERE table_name = '")
                .append(tableName)
                .append("'\n");

            spatialIndex
                .append("Insert into user_sdo_geom_metadata ")
                .append("(TABLE_NAME,COLUMN_NAME,DIMINFO,SRID)")
                .append("values ('")
                .append(tableName)
                .append("','")
                .append(field)
                .append("',MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',140.962,144.909,0.00001),")
                .append("MDSYS.SDO_DIM_ELEMENT('Y',-38.858,-33.98,0.00001)")
                .append( // support 3d index
                    ((GeometryDescriptor) desc).getCoordinateReferenceSystem() != null
                            && ((GeometryDescriptor) desc)
                                    .getCoordinateReferenceSystem()
                                    .getCoordinateSystem()
                                    .getDimension()
                                == 3
                        ? ", MDSYS.SDO_DIM_ELEMENT('Z',-100000, 100000, 1) ),"
                        : "),")
                .append(srid)
                .append(")\n");

            // ensure it's <= 30 characters to avoid Oracle exception
            String indexName =
                (tableName.length() <= 26 ? tableName : tableName.substring(0, 26)) + "_IDX";
            if (spatialIndexCounter > 0) {
              // to avoid duplicate index name when there are > 1 geometry in the same table
              indexName += spatialIndexCounter;
            }

            spatialIndex
                .append("CREATE INDEX \"")
                .append(indexName)
                .append("\" ON \"")
                .append(tableName)
                .append("\"(\"")
                .append(field)
                .append("\") ")
                .append("INDEXTYPE IS \"MDSYS\".\"SPATIAL_INDEX\"\n");
            spatialIndexCounter++;
          } else {
            type = Classes.getShortName(desc.getType().getBinding());
            if (type.equalsIgnoreCase("String")) {
              type = "NVARCHAR2(250)";
            } else if (type.equalsIgnoreCase("Double")) {
              type = "NUMBER";
            }
            // etc. assign as required
          }
          createParams.add(field + " " + type);
          j++;
        }
        // Add numeric PK for sorting
        fieldNames[j] = "PKEY";
        createParams.add("PKEY VARCHAR2(30)");
        buf.append(StringUtils.join(createParams.iterator(), ", "));
        buf.append(")\n");
        buf.append(
            "ALTER TABLE " + tableName + " ADD CONSTRAINT " + tableName + " PRIMARY KEY (PKEY)\n");
        // then insert rows
        SimpleFeature feature;
        FeatureId id;
        while (reader.hasNext()) {
          buf.append("INSERT INTO ").append(tableName).append("(");
          feature = reader.next();
          buf.append(StringUtils.join(fieldNames, ", "));
          buf.append(") ");
          buf.append("VALUES (");
          Collection<Property> properties = feature.getProperties();
          String[] values = new String[size];
          int valueIndex = 0;
          for (Property prop : properties) {
            Object value = prop.getValue();
            if (value instanceof Geometry) {
              // use wkt writer to convert geometry to string, so third dimension can be supported
              // if present.
              Geometry geom = (Geometry) value;
              value = new WKTWriter(geom.getCoordinate().z == Double.NaN ? 2 : 3).write(geom);
            }
            if (value == null || value.toString().equalsIgnoreCase("null")) {
              values[valueIndex] = "null";
            } else if (prop.getType() instanceof GeometryType) {
              int srid = getSrid(((GeometryType) prop.getType()));
              StringBuffer geomValue = new StringBuffer(parser + "('");
              geomValue.append(value).append("'");
              if (srid > -1) {
                // attach srid
                geomValue.append(", ").append(srid);
              }
              geomValue.append(")");
              values[valueIndex] = geomValue.toString();
            } else if (prop.getType().getBinding().getSimpleName().equalsIgnoreCase("DATE")) {
              values[valueIndex] = "TO_DATE('" + value + "', 'yyyy-MM-dd')";
            } else {
              values[valueIndex] = "'" + value + "'";
            }
            valueIndex++;
          }
          id = feature.getIdentifier();
          // insert primary key
          values[valueIndex] = "'" + id.toString() + "'";
          buf.append(StringUtils.join(values, ","));
          buf.append(")\n");
        }
      }
      buf.append(spatialIndex.toString());
      spatialIndex.delete(0, spatialIndex.length());
      if (buf.length() > 0) {
        this.sql = buf.toString();
      }
    }
  }