All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.backendless.persistence.Geometry Maven / Gradle / Ivy

The newest version!
package com.backendless.persistence;


public abstract class Geometry
{
  public static  T fromWKT( String wellKnownText )
  {
    return (T) new WKTParser().read( wellKnownText );
  }

  public static  T fromGeoJSON( String geoJson )
  {
    return (T) new GeoJSONParser().read( geoJson );
  }

  public static  T fromWKT( String wellKnownText, SpatialReferenceSystemEnum srs )
  {
    return (T) new WKTParser( srs ).read( wellKnownText );
  }

  public static  T fromGeoJSON( String geoJson, SpatialReferenceSystemEnum srs )
  {
    return (T) new GeoJSONParser( srs ).read( geoJson );
  }

  protected final SpatialReferenceSystemEnum srs;

  protected Geometry( SpatialReferenceSystemEnum srs )
  {
    if( srs == null )
      throw new IllegalArgumentException( "Spatial Reference System (SRS) cannot be null." );

    this.srs = srs;
  }

  public SpatialReferenceSystemEnum getSRS()
  {
    return srs;
  }

  abstract public String getGeojsonType();

  abstract public String getWktType();

  abstract String jsonCoordinatePairs();

  abstract String wktCoordinatePairs();

  public final String asGeoJSON()
  {
    return "{\"type\":\"" + this.getGeojsonType() + "\",\"coordinates\":" + this.jsonCoordinatePairs() + "}";
  }

  public final String asWKT()
  {
    return getWktType() + "(" + this.wktCoordinatePairs() + ")";
  }

  @Override
  public String toString()
  {
    return "'" + this.asWKT() + "'";
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy