Package com.spatial4j.core.exception

Examples of com.spatial4j.core.exception.InvalidShapeException


   */
  public void validate() throws InvalidShapeException {
    if (!validated) {
      IsValidOp isValidOp = new IsValidOp(geom);
      if (!isValidOp.isValid())
        throw new InvalidShapeException(isValidOp.getValidationError().toString());
      validated = true;
    }
  }
View Full Code Here


      if (type == 0) {
        shapes.add(readShape(dataInput));
      } else {
        Shape s = readShapeByTypeIfSupported(dataInput, type);
        if (s == null)
          throw new InvalidShapeException("Unsupported shape byte "+type);
        shapes.add(s);
      }
    }
    return ctx.makeCollection(shapes);
  }
View Full Code Here

          end = externalVal.length();
        }
      }
    }
    if (i != dimension) {
      throw new InvalidShapeException("incompatible dimension (" + dimension +
              ") and values (" + externalVal + ").  Only " + i + " values specified");
    }
    return out;
  }
View Full Code Here

          end = externalVal.length();
        }
      }
    }
    if (i != dimension) {
      throw new InvalidShapeException("incompatible dimension (" + dimension +
              ") and values (" + externalVal + ").  Only " + i + " values specified");
    }
    return out;
  }
View Full Code Here

   */
  public static final double[] parseLatitudeLongitude(double[] outLatLon, String latLonStr) throws InvalidShapeException {
    outLatLon = parsePointDouble(outLatLon, latLonStr, 2);

    if (outLatLon[0] < -90.0 || outLatLon[0] > 90.0) {
      throw new InvalidShapeException(
              "Invalid latitude: latitudes are range -90 to 90: provided lat: ["
                      + outLatLon[0] + "]");
    }


    if (outLatLon[1] < -180.0 || outLatLon[1] > 180.0) {
      throw new InvalidShapeException(
              "Invalid longitude: longitudes are range -180 to 180: provided lon: ["
                      + outLatLon[1] + "]");
    }

    return outLatLon;
View Full Code Here

   * If the first character is not a letter then it's assumed to be a point or rectangle. If that
   * doesn't work out then an {@link com.spatial4j.core.exception.InvalidShapeException} is thrown.
   */
  public static Shape readShapeOrNull(String str, SpatialContext ctx) throws InvalidShapeException {
    if (str == null || str.length() == 0) {
      throw new InvalidShapeException(str);
    }

    if (Character.isLetter(str.charAt(0))) {
      if (str.startsWith("Circle(") || str.startsWith("CIRCLE(")) {
        int idx = str.lastIndexOf(')');
        if (idx > 0) {
          String body = str.substring("Circle(".length(), idx);
          StringTokenizer st = new StringTokenizer(body, " ");
          String token = st.nextToken();
          Point pt;
          if (token.indexOf(',') != -1) {
            pt = readLatCommaLonPoint(token, ctx);
          } else {
            double x = Double.parseDouble(token);
            double y = Double.parseDouble(st.nextToken());
            pt = ctx.makePoint(x, y);
          }
          Double d = null;

          String arg = st.nextToken();
          idx = arg.indexOf('=');
          if (idx > 0) {
            String k = arg.substring(0, idx);
            if (k.equals("d") || k.equals("distance")) {
              d = Double.parseDouble(arg.substring(idx + 1));
            } else {
              throw new InvalidShapeException("unknown arg: " + k + " :: " + str);
            }
          } else {
            d = Double.parseDouble(arg);
          }
          if (st.hasMoreTokens()) {
            throw new InvalidShapeException("Extra arguments: " + st.nextToken() + " :: " + str);
          }
          if (d == null) {
            throw new InvalidShapeException("Missing Distance: " + str);
          }
          //NOTE: we are assuming the units of 'd' is the same as that of the spatial context.
          return ctx.makeCircle(pt, d);
        }
      }
      return null;//caller has opportunity to try other parsing
    }

    if (str.indexOf(',') != -1)
      return readLatCommaLonPoint(str, ctx);
    StringTokenizer st = new StringTokenizer(str, " ");
    double p0 = Double.parseDouble(st.nextToken());
    double p1 = Double.parseDouble(st.nextToken());
    if (st.hasMoreTokens()) {
      double p2 = Double.parseDouble(st.nextToken());
      double p3 = Double.parseDouble(st.nextToken());
      if (st.hasMoreTokens())
        throw new InvalidShapeException("Only 4 numbers supported (rect) but found more: " + str);
      return ctx.makeRectangle(p0, p2, p1, p3);
    }
    return ctx.makePoint(p0, p1);
  }
View Full Code Here

TOP

Related Classes of com.spatial4j.core.exception.InvalidShapeException

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.