コード例 #1
0
 public void characters(char[] ch, int start, int length) throws SAXException {
   if (placemarkactive && !CollectionUtils.intersection(visits, LEGALNAMES).isEmpty()) {
     if (currGeomHandler != null) {
       currGeomHandler.characters(ch, start, length);
     } else {
       String content = new String(ch, start, length).trim();
       if (content.length() > 0) {
         lastEltData += content;
         // System.out.println(lastEltName + "= " + content);
       }
     }
   }
 }
コード例 #2
0
    /**
     * SAX handler. Handle state and state transitions based on an element starting.
     *
     * @param uri Description of the Parameter
     * @param name Description of the Parameter
     * @param qName Description of the Parameter
     * @param atts Description of the Parameter
     * @exception SAXException Description of the Exception
     */
    public void startElement(String uri, String name, String qName, Attributes atts)
        throws SAXException {

      if (name.equals("Placemark")) {
        placemarkactive = true;
        row = new GeoTiffResultRow(); // new row result;
      }
      visits.add(name);
      if (placemarkactive && !CollectionUtils.intersection(visits, LEGALNAMES).isEmpty()) {
        // if (name.equalsIgnoreCase(GMLConstants.GML_POLYGON)
        //	|| name.equalsIgnoreCase(GMLConstants.GML_POINT)
        // || name.equalsIgnoreCase(GMLConstants.GML_MULTI_GEOMETRY)) {
        if (name.equalsIgnoreCase(GMLConstants.GML_MULTI_GEOMETRY)) {
          currGeomHandler = new GMLHandler(fact, null);
        }
        if (currGeomHandler != null) currGeomHandler.startElement(uri, name, qName, atts);
        if (currGeomHandler == null) {
          lastEltName = name;
          // System.out.println(name);
        }
      }
    }
コード例 #3
0
    /**
     * SAX handler - handle state information and transitions based on ending elements.
     *
     * @param uri Description of the Parameter
     * @param name Description of the Parameter
     * @param qName Description of the Parameter
     * @exception SAXException Description of the Exception
     */
    @SuppressWarnings({"unused", "unchecked"})
    public void endElement(String uri, String name, String qName) throws SAXException {
      // System.out.println("/" + name);
      // System.out.println("the ena name="+name);
      if (placemarkactive
          && !CollectionUtils.intersection(visits, LEGALNAMES).isEmpty()
          && currGeomHandler == null
          && !lastEltData.isEmpty()) {
        // System.out.println(lastEltName + " " + lastEltData);

        row.addPair(lastEltName, lastEltData);
      }
      lastEltData = "";
      if (name.equals("Placemark")) {
        placemarkactive = false;
        try {
          row.addPair(GeoTiffReader2.this.primarykey, KeyGenerator.Generate());
        } catch (Exception e) {
          e.printStackTrace();
          System.exit(0);
        }
        GeoTiffReader2.this.results.add(row);
      }
      visits.remove(name);

      if (currGeomHandler != null) {
        currGeomHandler.endElement(uri, name, qName);

        if (currGeomHandler.isGeometryComplete()) {
          Geometry g = currGeomHandler.getGeometry();

          WKTWriter wkt_writer = new WKTWriter();
          GMLWriter gml_writer = new GMLWriter();
          if (g.getClass().equals(com.vividsolutions.jts.geom.Point.class)) {
            Point geometry = (com.vividsolutions.jts.geom.Point) g;
            row.addPair("isEmpty", geometry.isEmpty());
            row.addPair("isSimple", geometry.isSimple());
            row.addPair("dimension", geometry.getCoordinates().length);
            row.addPair("coordinateDimension", geometry.getCoordinates().length);
            row.addPair("spatialDimension", geometry.getDimension()); // spatialdimension
            // <=
            // dimension
            // System.out.println(geometry.getCoordinate().x + " "
            // +geometry.getCoordinate().z);
            // System.out.println(geometry.get .getSRID());
            // CRS.
            String crs = "2311";
            if (crs == null) {
              System.err.println("No SRID specified. Aborting...");
              System.exit(-1);
            }

            row.addPair(
                "asWKT",
                "<http://www.opengis.net/def/crs/EPSG/0/" + crs + ">" + wkt_writer.write(geometry));
            row.addPair(
                "hasSerialization",
                "<http://www.opengis.net/def/crs/EPSG/0/" + crs + ">" + wkt_writer.write(geometry));
            // newrow.addPair("hasSerialization",
            // wkt_writer.write(geometry));
            gml_writer.setSrsName(crs);
            row.addPair("asGML", gml_writer.write(geometry).replaceAll("\n", " "));
            row.addPair("is3D", geometry.getDimension() == 3);
          } else {
            GeometryCollection geometry = (GeometryCollection) g;
            row.addPair("isEmpty", geometry.isEmpty());
            row.addPair("isSimple", geometry.isSimple());
            row.addPair("dimension", geometry.getCoordinates().length);
            row.addPair("coordinateDimension", geometry.getCoordinates().length);
            row.addPair("spatialDimension", geometry.getDimension()); // spatialdimension
            // <=
            // dimension
            // System.out.println(geometry.getCoordinate().x + " "
            // +geometry.getCoordinate().z);
            // System.out.println(geometry.get .getSRID());
            // CRS.
            String crs = "2323";
            if (crs == null) {
              System.err.println("No SRID specified. Aborting...");
              System.exit(-1);
            }
            // geometry.getNumPoints();
            // TODO spatialDimension??????
            // TODO coordinateDimension??????
            // Geometry geometry1=
            // (Geometry)sourceGeometryAttribute.getValue();
            // geometry1.transform(arg0, arg1)

            // sourceGeometryAttribute.ge

            row.addPair(
                "asWKT",
                "<http://www.opengis.net/def/crs/EPSG/0/" + crs + ">" + wkt_writer.write(geometry));
            row.addPair(
                "hasSerialization",
                "<http://www.opengis.net/def/crs/EPSG/0/" + crs + ">" + wkt_writer.write(geometry));
            // newrow.addPair("hasSerialization",
            // wkt_writer.write(geometry));
            gml_writer.setSrsName("http://www.opengis.net/def/crs/EPSG/0/" + crs);
            row.addPair("asGML", gml_writer.write(geometry).replaceAll("\n", " "));
            row.addPair("is3D", geometry.getDimension() == 3);
          }

          // System.out.println(g);

          // System.out.println(ww.write(g));
          geoms.add(g);

          // reset to indicate no longer parsing geometry
          currGeomHandler = null;
        }
      }
    }
コード例 #4
0
 public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
   if (currGeomHandler != null) currGeomHandler.ignorableWhitespace(ch, start, length);
 }