Package com.esri.gpt.framework.geometry

Examples of com.esri.gpt.framework.geometry.Envelope


        double xmax = jExt.getDouble("xmax");
        double ymax = jExt.getDouble("ymax");
        JSONObject jSpatialRef = jExt.getJSONObject("spatialReference");
        int wkid = jSpatialRef.getInt("wkid");

        Envelope envelope = new Envelope(xmin, ymin, xmax, ymax);
        envelope.setWkid(Integer.toString(wkid));

        return envelope;
      }
    } catch (JSONException ex) {
      // invalid JSON response
View Full Code Here


    throws OwsException, XPathExpressionException {

    // initialize
    LOGGER.finer("Parsing spatial clause for "+parent.getNodeName());
    String sErr = parent.getNodeName();
    Envelope envelope = spatialClause.getBoundingEnvelope();
    // TODO ensure that the discoverable is a geometry
    Discoverable discoverable = this.parsePropertyName(parent,xpath);
    spatialClause.setTarget(discoverable);

    /*
     *
     * gml:Envelope <attribute name="gid" type="ID" use="optional"/> <attribute
     * name="srsName" type="anyURI" use="optional"/>
     *
     * <element name="lowerCorner" type="gml:DirectPositionType"/> <attribute
     * name="gid" type="ID" use="optional"/> <attribute name="srsName"
     * type="anyURI" use="optional"/> space separated x y <element
     * name="upperCorner" type="gml:DirectPositionType"/> <attribute name="gid"
     * type="ID" use="optional"/> <attribute name="srsName" type="anyURI"
     * use="optional"/> space separated x y
     *
     * <element ref="gml:pos" minOccurs="2" maxOccurs="2"> both are
     * type="gml:DirectPositionType" (deprecated)
     *
     * <element ref="gml:coord" minOccurs="2" maxOccurs="2"/> <element X> <element
     * Y>
     *
     * <element ref="gml:coordinates"/> <attribute name="decimal" type="string"
     * use="optional" default="."/> <attribute name="cs" type="string"
     * use="optional" default=","/> <attribute name="ts" type="string"
     * use="optional" default=" "/>
     *
     * gml:Box <attribute name="gid" type="ID" use="optional"/> <attribute
     * name="srsName" type="anyURI" use="optional"/> <element ref="gml:coord"
     * minOccurs="2" maxOccurs="2"/> <element X> <element Y> <element
     * ref="gml:coordinates"/> <attribute name="decimal" type="string"
     * use="optional" default="."/> <attribute name="cs" type="string"
     * use="optional" default=","/> <attribute name="ts" type="string"
     * use="optional" default=" "/>
     *
     * gml:Point <attribute name="gid" type="ID" use="optional"/> <attribute
     * name="srsName" type="anyURI" use="optional"/> <element ref="gml:coord"/>
     * <element X> <element Y> <element ref="gml:coordinates"/> <attribute
     * name="decimal" type="string" use="optional" default="."/> <attribute
     * name="cs" type="string" use="optional" default=","/> <attribute name="ts"
     * type="string" use="optional" default=" "/>
     *
     * gml:LineString <attribute name="gid" type="ID" use="optional"/> <attribute
     * name="srsName" type="anyURI" use="optional"/> <element ref="gml:coord"
     * minOccurs="2" maxOccurs="unbounded"/> <element X> <element Y> <element
     * ref="gml:coordinates"/> <attribute name="decimal" type="string"
     * use="optional" default="."/> <attribute name="cs" type="string"
     * use="optional" default=","/> <attribute name="ts" type="string"
     * use="optional" default=" "/>
     */

    // determine the envelope
    Node ndSpatial = (Node)xpath.evaluate("gml:Envelope",parent,XPathConstants.NODE);
    if (ndSpatial == null) {
      ndSpatial = (Node)xpath.evaluate("gml:Box",parent,XPathConstants.NODE);
      if (ndSpatial == null) {
        ndSpatial = (Node)xpath.evaluate("gml:Point",parent,XPathConstants.NODE);
      }
    }
    if (ndSpatial != null) {
      LOGGER.finest("Parsing "+ndSpatial.getNodeName()+"...");
      sErr += "."+ndSpatial.getNodeName();
      spatialClause.setSrsName(xpath.evaluate("@srsName",ndSpatial));
      Node ndLower = (Node)xpath.evaluate("gml:lowerCorner",ndSpatial,XPathConstants.NODE);
      Node ndUpper = (Node)xpath.evaluate("gml:upperCorner",ndSpatial,XPathConstants.NODE);
      Node ndCoords = (Node)xpath.evaluate("gml:coordinates",ndSpatial,XPathConstants.NODE);
      NodeList nlCoord = (NodeList)xpath.evaluate("gml:coord",ndSpatial,XPathConstants.NODESET);

      // handle a lower and upper boundary
      if ((ndLower != null) && (ndUpper != null)) {
        String sLower = Val.chkStr(ndLower.getTextContent());
        String sUpper = Val.chkStr(ndUpper.getTextContent());
        LOGGER.finest("Parsing gml:lowerCorner=\""+sLower+"\" gml:upperCorner=\""+sUpper+"\"");
        String[] xyLower = Val.tokenize(sLower," ");
        String[] xyUpper = Val.tokenize(sUpper," ");
        if ((xyLower.length == 2) && (xyUpper.length == 2)) {
          envelope.put(xyLower[0],xyLower[1],xyUpper[0],xyUpper[1]);
        }

        // handle a delimited list of coordinates
      } else if (ndCoords != null) {

        // separators: decimal, ts (between coordinate pairs), cs (between x/y values)
        char cDecSep = '.';
        String decSep = xpath.evaluate("@decimal",ndCoords);
        if ((decSep != null) && (decSep.length() == 1)) cDecSep = decSep.charAt(0);
        String tsSep = xpath.evaluate("@ts",ndCoords);
        if ((tsSep == null) || (tsSep.length() != 1)) tsSep = " ";
        String csSep = xpath.evaluate("@cs", ndCoords);
        if ((csSep == null) || (csSep.length() != 1)) csSep = ",";
        String sepMsg = "decimal=\""+cDecSep+"\" ts=\""+tsSep+"\" cs=\""+csSep+"\"";

        // collect individual string values
        String sCordinates = Val.chkStr(ndCoords.getTextContent());
        LOGGER.finest("Parsing gml:coordinates "+sepMsg+" coordinates=\""+sCordinates+"\"");
        ArrayList<String> values = new ArrayList<String>();
        String[] tsValues = Val.tokenize(sCordinates,tsSep);
        for (String tsValue : tsValues) {
          String[] csValues = Val.tokenize(tsValue,csSep);
          for (String csValue: csValues) {
            LOGGER.finer("Adding coordinate value: "+csValue);
            values.add(csValue.replace(cDecSep,'.'));
          }
        }

        // determine the minimum and maximum envelope values from the coordinate list
        for (int i=0; i<values.size(); i=i+2) {
          try {
            LOGGER.finest("Handling coordinate: "+values.get(i)+" "+values.get(i + 1));
            double x = Double.parseDouble(values.get(i));
            double y = Double.parseDouble(values.get(i+1));
            envelope.merge(new Envelope(x,y,x,y));
          } catch (NumberFormatException e) {
            LOGGER.warning(e.getMessage());
          }
        }

      // handle a collection of coordinate elements
      } else if (nlCoord.getLength() > 0) {
        LOGGER.finest("Parsing gml:coord elements...");
        for (int i=0; i< nlCoord.getLength(); i++) {
          Node ndX = (Node)xpath.evaluate("gml:X",nlCoord.item(i),XPathConstants.NODE);
          Node ndY = (Node)xpath.evaluate("gml:Y",nlCoord.item(i),XPathConstants.NODE);
          if ((ndX != null) && (ndY != null)) {
            try {
              LOGGER.finest("Handling coordinate: "+ndX.getTextContent()+" "+ndY.getTextContent());
              double x = Double.parseDouble(ndX.getTextContent());
              double y = Double.parseDouble(ndY.getTextContent());
              envelope.merge(new Envelope(x,y,x,y));
            } catch (NumberFormatException e) {
              LOGGER.warning(e.getMessage());
            }
          }
        }
      }

    }

    // add the clause if the envelope is not empty
    if (!envelope.isEmpty()) {
      logicalClause.getClauses().add(spatialClause);
    } else {
      String msg = sErr+" - the geometry of the spatial operand was not valid.";
      throw new OwsException(OwsException.OWSCODE_InvalidParameterValue,parent.getLocalName(),msg);
    }
View Full Code Here

* @return the enclosing envelope (never null)
*/
public Envelope getEnclosingEnvelope() {
 
  //TODO: Check with urban about merging envelopes
  Envelope encEnv = null;
  Envelope recordEnvelope = null;
 
  for(SearchResultRecord record : this.getRecords()) {
    recordEnvelope = record.getEnvelope();
    if(encEnv == null) {
      encEnv = new Envelope();
      encEnv.setMaxX(recordEnvelope.getMaxX());
      encEnv.setMaxY(recordEnvelope.getMaxY());
      encEnv.setMinX(recordEnvelope.getMinX());
      encEnv.setMinY(recordEnvelope.getMinY());
      continue;
    }
   encEnv.merge(recordEnvelope);
  
  }
View Full Code Here

  StringBuffer jsRecords = new StringBuffer();
  jsRecords.append("{ \"records\" : [");
  SearchResultRecords records = this.getRecords();
  int index = 0;
  for(SearchResultRecord record : records ) {
    Envelope recEnvelope = record.getEnvelope().clone();
    //Object obj = record.getObjectMap().get(key)
    if(recEnvelope.getMaxY() > 90){
      recEnvelope.setMaxY(90);
    }
    if(recEnvelope.getMinY() < -90) {
      recEnvelope.setMinY(-90);
    }
    jsRecords.append(" {\"bboxes\" : [");
    Envelope[] envs = this.internationalDatelineSplit(recEnvelope);
    int i = 0;
    Envelope enclosingEnvelope = null;
    do {
      
      if(i > 0){
        jsRecords.append(",");
      }
      jsRecords
      .append("{")
      .append( " \"isDefaultGeometry\"  : ").append(record.isDefaultGeometry()).append(",")
      .append( " \"maxX\"  : ").append(envs[i].getMaxX()).append(",")
      .append( " \"maxY\"  : ").append(envs[i].getMaxY()).append(",")
      .append( " \"minX\"  : ").append(envs[i].getMinX()).append(",")
      .append( " \"minY\"  : ").append(envs[i].getMinY())
      .append("}");
     
      if(enclosingEnvelope == null) {
        enclosingEnvelope = envs[i];
      } else {
        enclosingEnvelope.merge(envs[i]);
      }
      i++;
     
    } while(i < envs.length);
   
    jsRecords.append("], \"enclosingEnvelope\" : ")
      .append("{")
      .append( " \"maxX\"  : ").append(enclosingEnvelope.getMaxX()).append(",")
      .append( " \"maxY\"  : ").append(enclosingEnvelope.getMaxY()).append(",")
      .append( " \"minX\"  : ").append(enclosingEnvelope.getMinX()).append(",")
      .append( " \"minY\"  : ").append(enclosingEnvelope.getMinY())
      .append("}");
   
    jsRecords.append(", \"uuid\" : ").append("\"")
      .append(Val.escapeStrForJson(record.getUuid()))
      .append("\"");
View Full Code Here

*/
private Envelope[] internationalDatelineSplit(Envelope envelope) {
  if(envelope.getMaxX() >= envelope.getMinX()) {
    return new Envelope[]{envelope};
  }
  Envelope leftEnvelope = new Envelope();
  Envelope rightEnvelope = new Envelope();
  leftEnvelope.setMaxY(envelope.getMaxY());
  leftEnvelope.setMinY(envelope.getMinY());
  leftEnvelope.setMinX(-180);
  leftEnvelope.setMaxX(envelope.getMaxX());
 
  rightEnvelope.setMaxY(envelope.getMaxY());
  rightEnvelope.setMinY(envelope.getMinY());
  rightEnvelope.setMaxX(180);
  rightEnvelope.setMinX(envelope.getMinX());
   
  return new Envelope[]{leftEnvelope, rightEnvelope};
}
View Full Code Here

  private String envelopeToString(com.esri.arcgisws.Envelope E) {
    if (E instanceof EnvelopeN) {
      EnvelopeN e = (EnvelopeN) E;

      // project envelope
      Envelope gptEnvelope = new Envelope(e.getXMin(), e.getYMin(), e.getXMax(), e.getYMax());
      if (e.getSpatialReference()!=null && e.getSpatialReference().getWKID()!=null) {
        gptEnvelope.setWkid(e.getSpatialReference().getWKID().toString());
        List<Envelope> envelopes = Arrays.asList(new Envelope[]{gptEnvelope});
        try {
          List<Envelope> projectedEnvelopes = gs.project(envelopes, "4326");
          if (projectedEnvelopes!=null && !projectedEnvelopes.isEmpty()) {
            Envelope pe = projectedEnvelopes.get(0);
            String envelope = ""+pe.getMinX()+","+pe.getMinY()+","+pe.getMaxX()+","+pe.getMaxY();
            return envelope;
          }
        } catch (Exception ex) {
          LOGGER.log(Level.WARNING, "Error projecting envelope.", ex);
        }
View Full Code Here

      if (oValue != null) {
        if (meaning.getValueType().equals(PropertyValueType.GEOMETRY)) {
          if (oValue instanceof Envelope) {
           
            // TODO include multiple envelope types in the response
            Envelope env = (Envelope)oValue;
            String sLower = env.getMinX()+" "+env.getMinY();
            String sUpper = env.getMaxX()+" "+env.getMaxY();
           
            Element elField = responseDom.createElement("ows:WGS84BoundingBox");
            Element elLower = responseDom.createElement("ows:LowerCorner");
            Element elUpper = responseDom.createElement("ows:UpperCorner");
            elLower.appendChild(responseDom.createTextNode(sLower));
View Full Code Here

            if (ndWmsCapabilities == null) {
              ndWmsCapabilities = (Node) xPath.evaluate("/WMT_MS_Capabilities", docContent, XPathConstants.NODE);
            }

            if (ndWmsCapabilities != null) {
              final Envelope extent = readExtent(xPath, ndWmsCapabilities);
              setter.set(new WMSRenderer() {

                @Override
                protected Envelope getExtent() {
                  return extent;
View Full Code Here

    if (EX_GeographicBoundingBox != null) {
      return extractExtent(xPath, EX_GeographicBoundingBox, new String[]{"westBoundLongitude", "southBoundLatitude", "eastBoundLongitude", "northBoundLatitude"}, wkid);
    } else {
      NodeList nodes = (NodeList) xPath.evaluate("//EX_GeographicBoundingBox", ndWmsCapabilities, XPathConstants.NODESET);
      if (nodes.getLength() > 0) {
        Envelope envelope = new Envelope();
        envelope.setWkid(wkid);
        for (int i = 0; i < nodes.getLength(); i++) {
          Node node = nodes.item(i);
          Envelope e = extractExtent(xPath, node, new String[]{"westBoundLongitude", "southBoundLatitude", "eastBoundLongitude", "northBoundLatitude"}, wkid);
          if (e != null) {
            envelope.merge(e);
          }
        }
        if (envelope.hasSize())
View Full Code Here

    if (sMinX.length() > 0 && sMaxX.length() > 0 && sMinY.length() > 0 && sMaxY.length() > 0) {
      double minx = Val.chkDbl(sMinX, -180.0);
      double maxx = Val.chkDbl(sMaxX, 180.0);
      double miny = Val.chkDbl(sMinY, -90.0);
      double maxy = Val.chkDbl(sMaxY, 90.0);
      Envelope envelope = new Envelope(minx, miny, maxx, maxy);
      envelope.setWkid(wkid);
      return envelope;
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of com.esri.gpt.framework.geometry.Envelope

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.