Example #1
0
from geoscript import core
import geom


class LineString(_LineString):
    """
  A LineString geometry.

  *coords* is a variable list of ``list``/``tuple`` arguments.

  >>> LineString([1,2], [3,4])
  LINESTRING (1 2, 3 4)
  """
    def __init__(self, *coords):

        if len(coords) == 1 and isinstance(coords[0], _LineString):
            ls = coords[0]
        else:
            l = []
            for c in coords:
                l.append(Coordinate(c[0], c[1]))
                if len(c) > 2:
                    l[-1].z = c[2]
            ls = geom._factory.createLineString(l)

        _LineString.__init__(self, ls.coordinateSequence, geom._factory)


geom._enhance(LineString)
core.registerTypeMapping(_LineString, LineString)
Example #2
0
from com.vividsolutions.jts.geom import Coordinate
from com.vividsolutions.jts.geom import LinearRing as _LinearRing
from linestring import LineString
import geom

class LinearRing(_LinearRing):
  """
  A LineString geometry in which the first and last coordinates are identical forming a closed ring. The arguments for contstructing a ``LinearRing`` are identical to those for constructing a :class:`LineString`. 

  >>> LinearRing([1,2], [3,4], [4,5], [1,2])
  LINEARRING (1 2, 3 4, 4 5, 1 2)
  """

  def __init__(self, *coords):
    if len(coords) == 1 and isinstance(coords[0], _LinearRing):
      _LinearRing.__init__(self, coords[0].coordinateSequence) 
    else:
      l = LineString(*coords)
      _LinearRing.__init__(self, l.coordinateSequence, geom._factory)

geom._enhance(LinearRing)
Example #3
0
import geom

class MultiPolygon(_MultiPolygon):
  """
  A MultiPolygon geometry.

  *polygons* is a variable number of multidimensional lists of ``list``/``tuple``.

  >>> MultiPolygon( [ [[1,2],[3,4],[5,6],[1,2]] ],  [ [[7,8], [9,10], [11,12], [7,8]] ] )
  MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)), ((7 8, 9 10, 11 12, 7 8)))

  *polygons* may also be specified as a variable number of :class:`Polygon` arguments.

  >>> MultiPolygon(Polygon([[1,2], [3,4], [5,6], [1,2]]), Polygon([[7,8], [9,10], [11,12], [7,8]]))
  MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)), ((7 8, 9 10, 11 12, 7 8)))
  
  """

  def __init__(self, *polygons):
  
    if isinstance(polygons[0], _MultiPolygon):
       mp = polygons[0]
       polygons = [mp.getGeometryN(i) for i in range(mp.numGeometries)]
    elif isinstance(polygons[0], (list,tuple)):
       polygons = [Polygon(*p) for p in polygons]

    _MultiPolygon.__init__(self, polygons, geom._factory)

geom._enhance(MultiPolygon)
core.registerTypeMapping(_MultiPolygon, MultiPolygon)
Example #4
0
from com.vividsolutions.jts.geom import Coordinate
from com.vividsolutions.jts.geom import LinearRing as _LinearRing
from linestring import LineString
from geoscript import core
import geom


class LinearRing(_LinearRing):
    """
  A LineString geometry in which the first and last coordinates are identical forming a closed ring. The arguments for contstructing a ``LinearRing`` are identical to those for constructing a :class:`LineString`. 

  >>> LinearRing([1,2], [3,4], [4,5], [1,2])
  LINEARRING (1 2, 3 4, 4 5, 1 2)
  """
    def __init__(self, *coords):
        if len(coords) == 1 and isinstance(coords[0], _LinearRing):
            _LinearRing.__init__(self, coords[0].coordinateSequence)
        else:
            l = LineString(*coords)
            _LinearRing.__init__(self, l.coordinateSequence, geom._factory)


geom._enhance(LinearRing)
core.registerTypeMapping(_LinearRing, LinearRing)
Example #5
0
      return percentAlong
  
  def placePoint(self, *coord):
      """
      Place or snap the :class:`point <geoscript.geom.Point>` to the `LineString <geoscript.geom.LineString>`. This method returns a new placed `Point <geoscript.geom.Point>`.

      *coord* A :class:`Point <geoscript.geom.Point>` or a variable list of x,y,z arguments.

      """
      point = coord[0] if isinstance(coord[0], Point) else Point(*coord)
      indexedLine = LengthIndexedLine(self)
      position = indexedLine.indexOf(point.coordinate)
      coord = indexedLine.extractPoint(position)
      return Point(coord.x, coord.y)
  
  def subLine(self, start, end):
      """
      Extract a sub :class:`LineString <geoscript.geom.LineString>` using a start and end position.  Both positions are numbers between 0 and 1.  A new :class:`LineString <geoscript.geom.LineString>` is returned.

      *start* The start position between 0 and 1
      
      *end* The end position between 0 and 1

      """
      indexedLine = LengthIndexedLine(self)
      length = self.getLength()
      return LineString(indexedLine.extractLine(start * length, end * length))

geom._enhance(LineString)
core.registerTypeMapping(_LineString, LineString)
Example #6
0
from com.vividsolutions.jts.geom import Coordinate
from com.vividsolutions.jts.geom import Point as _Point
import geom

class Point(_Point):
  """
  A Point geometry.

  *coord* is a variable list of x, y, z arguments.

  >>> Point(1,2)
  POINT (1 2)
  """

  def __init__(self, *coord):

    if len(coord) == 1 and isinstance(coord[0], _Point):
      p = coord[0]
    else:
      c = Coordinate(coord[0], coord[1])
      if len(coord) > 2:
        c.z = coord[2]
      p = geom._factory.createPoint(c)

    _Point.__init__(self, p.coordinateSequence, geom._factory)

geom._enhance(Point)
Example #7
0
import geom

class Polygon(_Polygon):
  """
  A Polygon geometry.

  *rings* is a variable number of lists of ``list``/``tuple`` arguments defining the rings of the polygon. The first argument is the outer ring and remaining arguments are holes. 

  >>> Polygon( [[1,2], [3,4], [5,6], [1,2]])
  POLYGON ((1 2, 3 4, 5 6, 1 2))
 
  >>> Polygon( [[-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]], [[-5,-5],[-1,-5],[-3,-2],[-5,-5]], [[5,5],[9,5],[7,7],[5,5]] )
  POLYGON ((-10 -10, 10 -10, 10 10, -10 10, -10 -10), (-5 -5, -1 -5, -3 -2, -5 -5), (5 5, 9 5, 7 7, 5 5))

  *rings* may also be specified as a variable number of :class:`LinearRing` objects.

  >>> Polygon( LinearRing([-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]), LinearRing([-5,-5],[-1,-5],[-3,-2],[-5,-5]), LinearRing([5,5],[9,5],[7,7],[5,5]) )
  POLYGON ((-10 -10, 10 -10, 10 10, -10 10, -10 -10), (-5 -5, -1 -5, -3 -2, -5 -5), (5 5, 9 5, 7 7, 5 5))
  """

  def __init__(self, *rings):
    if isinstance(rings[0], _Polygon):
      p = rings[0]
      _Polygon.__init__(self, p.exteriorRing, [p.getInteriorRingN(i) for i in range(p.numInteriorRing)], geom._factory)
    else:
      lr = [r if isinstance(r,LinearRing) else LinearRing(*r) for r in rings ]
      _Polygon.__init__(self, lr[0], lr[1:], geom._factory)

geom._enhance(Polygon)
core.registerTypeMapping(_Polygon, Polygon)
Example #8
0
class MultiPoint(_MultiPoint):
    """
  A MultiPoint goemetry.

  *points* is a variable number of ``list``/``tuple`` arguments. 

  >>> MultiPoint([1,2], [3,4])
  MULTIPOINT ((1 2), (3 4))

  *points* may also be specified as a variable number of :class:`Point` arguments. 

  >>> MultiPoint(Point(1,2), Point(3,4))
  MULTIPOINT ((1 2), (3 4))
   
  """

    def __init__(self, *points):

        if isinstance(points[0], _MultiPoint):
            mp = points[0]
            points = [mp.getGeometryN(i) for i in range(mp.numGeometries)]
        elif isinstance(points[0], (list, tuple)):
            points = [Point(*p) for p in points]

        _MultiPoint.__init__(self, points, geom._factory)


geom._enhance(MultiPoint)
core.registerTypeMapping(_MultiPoint, MultiPoint)
Example #9
0
from linestring import LineString
import geom

class MultiLineString(_MultiLineString):
  """
  A MultiLineString geometry.

  *linestrings* is a variable number of lists of ``list``/``tuple`` arugments.

  >>> MultiLineString([[1,2],[3,4]], [[5,6],[7,8]])
  MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))

  *linestrings* may also be specified as multiple :class:`LineString` arguments.

  >>> MultiLineString(LineString([1,2],[3,4]), LineString([5,6],[7,8]))
  MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))

  """

  def __init__(self, *linestrings):
  
    if isinstance(linestrings[0], _MultiLineString):
      mls = linestrings[0]  
      linestrings = [mls.getGeometryN(i) for i in range(mls.numGeometries)]
    elif isinstance(linestrings[0], (list,tuple)):
      linestrings = [LineString(*l) for l in linestrings]

    _MultiLineString.__init__(self, linestrings, geom._factory)

geom._enhance(MultiLineString)
Example #10
0
import geom

class Polygon(_Polygon):
  """
  A Polygon geometry.

  *rings* is a variable number of lists of ``list``/``tuple`` arguments defining the rings of the polygon. The first argument is the outer ring and remaining arguments are holes. 

  >>> Polygon( [[1,2], [3,4], [5,6], [1,2]])
  POLYGON ((1 2, 3 4, 5 6, 1 2))
 
  >>> Polygon( [[-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]], [[-5,-5],[-1,-5],[-3,-2],[-5,-5]], [[5,5],[9,5],[7,7],[5,5]] )
  POLYGON ((-10 -10, 10 -10, 10 10, -10 10, -10 -10), (-5 -5, -1 -5, -3 -2, -5 -5), (5 5, 9 5, 7 7, 5 5))

  *rings* may also be specified as a variable number of :class:`LinearRing` objects.

  >>> Polygon( LinearRing([-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]), LinearRing([-5,-5],[-1,-5],[-3,-2],[-5,-5]), LinearRing([5,5],[9,5],[7,7],[5,5]) )
  POLYGON ((-10 -10, 10 -10, 10 10, -10 10, -10 -10), (-5 -5, -1 -5, -3 -2, -5 -5), (5 5, 9 5, 7 7, 5 5))
  """

  def __init__(self, *rings):
    if isinstance(rings[0], _Polygon):
      p = rings[0]
      _Polygon.__init__(self, p.exteriorRing, [p.getInteriorRingN(i) for i in range(p.numInteriorRing)], geom._factory)
    else:
      lr = [r if isinstance(r,LinearRing) else LinearRing(*r) for r in rings ]
      _Polygon.__init__(self, lr[0], lr[1:], geom._factory)

geom._enhance(Polygon)
core.registerTypeMapping(_Polygon, Polygon)
Example #11
0

class MultiPolygon(_MultiPolygon):
    """
  A MultiPolygon geometry.

  *polygons* is a variable number of multidimensional lists of ``list``/``tuple``.

  >>> MultiPolygon( [ [[1,2],[3,4],[5,6],[1,2]] ],  [ [[7,8], [9,10], [11,12], [7,8]] ] )
  MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)), ((7 8, 9 10, 11 12, 7 8)))

  *polygons* may also be specified as a variable number of :class:`Polygon` arguments.

  >>> MultiPolygon(Polygon([[1,2], [3,4], [5,6], [1,2]]), Polygon([[7,8], [9,10], [11,12], [7,8]]))
  MULTIPOLYGON (((1 2, 3 4, 5 6, 1 2)), ((7 8, 9 10, 11 12, 7 8)))
  
  """
    def __init__(self, *polygons):

        if isinstance(polygons[0], _MultiPolygon):
            mp = polygons[0]
            polygons = [mp.getGeometryN(i) for i in range(mp.numGeometries)]
        elif isinstance(polygons[0], (list, tuple)):
            polygons = [Polygon(*p) for p in polygons]

        _MultiPolygon.__init__(self, polygons, geom._factory)


geom._enhance(MultiPolygon)
core.registerTypeMapping(_MultiPolygon, MultiPolygon)
Example #12
0
from org.geotools.geometry.jts import CompoundCurve as _CompoundCurve
from org.geotools.geometry.jts import CurvedGeometryFactory
from linestring import LineString
from circularstring import CircularString
from java.lang import Double
from geoscript import core
import geom

class CompoundCurve(_CompoundCurve):
    """
    A CompoundCurve geometry.

    *linestrings* is a variable list of ``LineStrings`` or ``CircularStrings`` arguments.

    >>> CompoundCurve(CircularString([10.0, 10.0], [0.0, 20.0], [-10.0, 10.0]), LineString([-10.0, 10.0], [-10.0, 0.0], [10.0, 0.0], [5.0, 5.0]))
    COMPOUNDCURVE(CIRCULARSTRING(10.0 10.0, 0.0 20.0, -10.0 10.0), (-10.0 10.0, -10.0 0.0, 10.0 0.0, 5.0 5.0))
    """

    def __init__(self, *linestrings):
        tolerance = Double.MAX_VALUE    
        if len(linestrings) == 1 and isinstance(linestrings[0], _CompoundCurve):
            cc = linestrings[0]
            linestrings = cc.components

        cgf = CurvedGeometryFactory(tolerance)
        _CompoundCurve.__init__(self, linestrings, cgf, tolerance)

geom._enhance(CompoundCurve)
core.registerTypeMapping(_CompoundCurve, CompoundCurve)

Example #13
0
from org.geotools.geometry.jts import CurvedGeometryFactory
from linestring import LineString
from circularstring import CircularString
from java.lang import Double
from geoscript import core
import geom

class CompoundRing(_CompoundRing):
    """
    A CompoundRing geometry.

    *linestrings* is a variable list of ``LineStrings`` or ``CircularStrings`` arguments.

    >>> CompoundRing(CircularString([10.0, 10.0], [0.0, 20.0], [-10.0, 10.0]),LineString([-10.0, 10.0], [-10.0, 0.0], [10.0, 0.0], [10.0, 10.0]))
    COMPOUNDCURVE(CIRCULARSTRING(10.0 10.0, 0.0 20.0, -10.0 10.0), (-10.0 10.0, -10.0 0.0, 10.0 0.0, 10.0 10.0))
    """

    def __init__(self, *linestrings):
        tolerance = Double.MAX_VALUE    
        if len(linestrings) == 1 and isinstance(linestrings[0], _CompoundRing):
            cc = linestrings[0]
            linestrings = cc.components

        cgf = CurvedGeometryFactory(tolerance)
        _CompoundRing.__init__(self, linestrings, cgf, tolerance)

geom._enhance(CompoundRing)
core.registerTypeMapping(_CompoundRing, CompoundRing)


Example #14
0

class MultiPoint(_MultiPoint):
    """
  A MultiPoint goemetry.

  *points* is a variable number of ``list``/``tuple`` arguments. 

  >>> MultiPoint([1,2], [3,4])
  MULTIPOINT ((1 2), (3 4))

  *points* may also be specified as a variable number of :class:`Point` arguments. 

  >>> MultiPoint(Point(1,2), Point(3,4))
  MULTIPOINT ((1 2), (3 4))
   
  """
    def __init__(self, *points):

        if isinstance(points[0], _MultiPoint):
            mp = points[0]
            points = [mp.getGeometryN(i) for i in range(mp.numGeometries)]
        elif isinstance(points[0], (list, tuple)):
            points = [Point(*p) for p in points]

        _MultiPoint.__init__(self, points, geom._factory)


geom._enhance(MultiPoint)
core.registerTypeMapping(_MultiPoint, MultiPoint)
Example #15
0
class MultiLineString(_MultiLineString):
    """
  A MultiLineString geometry.

  *linestrings* is a variable number of lists of ``list``/``tuple`` arugments.

  >>> MultiLineString([[1,2],[3,4]], [[5,6],[7,8]])
  MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))

  *linestrings* may also be specified as multiple :class:`LineString` arguments.

  >>> MultiLineString(LineString([1,2],[3,4]), LineString([5,6],[7,8]))
  MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))

  """
    def __init__(self, *linestrings):

        if isinstance(linestrings[0], _MultiLineString):
            mls = linestrings[0]
            linestrings = [
                mls.getGeometryN(i) for i in range(mls.numGeometries)
            ]
        elif isinstance(linestrings[0], (list, tuple)):
            linestrings = [LineString(*l) for l in linestrings]

        _MultiLineString.__init__(self, linestrings, geom._factory)


geom._enhance(MultiLineString)
core.registerTypeMapping(_MultiLineString, MultiLineString)
    *coords* is a variable list of ``list``/``tuple`` arguments.

    >>> CircularString([1,1], [5,5], [2,2])
    CIRCULARSTRING(1.0 1.0, 5.0 5.0, 2.0 2.0)
    """

    def __init__(self, *coords):
        tolerance = Double.MAX_VALUE
        if len(coords) == 1 and isinstance(coords[0], _CircularString):
            cs = coords[0].coordinateSequence
        else:
            l = []
            for c in coords:
                l.append(Coordinate(c[0], c[1]))
                if len(c) > 2:
                    l[-1].z = c[2]
            cs = geom._factory.coordinateSequenceFactory.create(l)

        doubles = []
        for c in cs.toCoordinateArray():
            doubles.append(c.x)
            doubles.append(c.y)

        cgf = CurvedGeometryFactory(tolerance)
        _CircularString.__init__(self, doubles, cgf, tolerance)


geom._enhance(CircularString)
core.registerTypeMapping(_CircularString, CircularString)
Example #17
0
    A CircularRing geometry.

    *coords* is a variable list of ``list``/``tuple`` arguments.

    >>> CircularRing([1,1], [5,5], [2,2], [4,5], [1,1])
    CIRCULARSTRING (1.0 1.0, 5.0 5.0, 2.0 2.0, 4.0 5.0, 1.0 1.0)
    """

    def __init__(self, *coords):
        tolerance = Double.MAX_VALUE    
        if len(coords) == 1 and isinstance(coords[0], _CircularRing):
          cs = coords[0].coordinateSequence
        else:
          l = []
          for c in coords:
            l.append( Coordinate(c[0],c[1]) )
            if len(c) > 2:
              l[-1].z = c[2]
          cs = geom._factory.coordinateSequenceFactory.create(l)
        
        doubles = []
        for c in cs.toCoordinateArray():
            doubles.append(c.x)
            doubles.append(c.y)

        cgf = CurvedGeometryFactory(tolerance)
        _CircularRing.__init__(self, doubles, cgf, tolerance)

geom._enhance(CircularRing)
core.registerTypeMapping(_CircularRing, CircularRing)
Example #18
0
from org.geotools.geometry.jts import CompoundRing as _CompoundRing
from org.geotools.geometry.jts import CurvedGeometryFactory
from linestring import LineString
from circularstring import CircularString
from java.lang import Double
from geoscript import core
import geom


class CompoundRing(_CompoundRing):
    """
    A CompoundRing geometry.

    *linestrings* is a variable list of ``LineStrings`` or ``CircularStrings`` arguments.

    >>> CompoundRing(CircularString([10.0, 10.0], [0.0, 20.0], [-10.0, 10.0]),LineString([-10.0, 10.0], [-10.0, 0.0], [10.0, 0.0], [10.0, 10.0]))
    COMPOUNDCURVE(CIRCULARSTRING(10.0 10.0, 0.0 20.0, -10.0 10.0), (-10.0 10.0, -10.0 0.0, 10.0 0.0, 10.0 10.0))
    """
    def __init__(self, *linestrings):
        tolerance = Double.MAX_VALUE
        if len(linestrings) == 1 and isinstance(linestrings[0], _CompoundRing):
            cc = linestrings[0]
            linestrings = cc.components

        cgf = CurvedGeometryFactory(tolerance)
        _CompoundRing.__init__(self, linestrings, cgf, tolerance)


geom._enhance(CompoundRing)
core.registerTypeMapping(_CompoundRing, CompoundRing)
Example #19
0
    A CircularRing geometry.

    *coords* is a variable list of ``list``/``tuple`` arguments.

    >>> CircularRing([1,1], [5,5], [2,2], [4,5], [1,1])
    CIRCULARSTRING(1.0 1.0, 5.0 5.0, 2.0 2.0, 4.0 5.0, 1.0 1.0)
    """
    def __init__(self, *coords):
        tolerance = Double.MAX_VALUE
        if len(coords) == 1 and isinstance(coords[0], _CircularRing):
            cs = coords[0].coordinateSequence
        else:
            l = []
            for c in coords:
                l.append(Coordinate(c[0], c[1]))
                if len(c) > 2:
                    l[-1].z = c[2]
            cs = geom._factory.coordinateSequenceFactory.create(l)

        doubles = []
        for c in cs.toCoordinateArray():
            doubles.append(c.x)
            doubles.append(c.y)

        cgf = CurvedGeometryFactory(tolerance)
        _CircularRing.__init__(self, doubles, cgf, tolerance)


geom._enhance(CircularRing)
core.registerTypeMapping(_CircularRing, CircularRing)
Example #20
0
    A CircularString geometry.

    *coords* is a variable list of ``list``/``tuple`` arguments.

    >>> CircularString([1,1], [5,5], [2,2])
    CIRCULARSTRING(1.0 1.0, 5.0 5.0, 2.0 2.0)
    """
    def __init__(self, *coords):
        tolerance = Double.MAX_VALUE
        if len(coords) == 1 and isinstance(coords[0], _CircularString):
            cs = coords[0].coordinateSequence
        else:
            l = []
            for c in coords:
                l.append(Coordinate(c[0], c[1]))
                if len(c) > 2:
                    l[-1].z = c[2]
            cs = geom._factory.coordinateSequenceFactory.create(l)

        doubles = []
        for c in cs.toCoordinateArray():
            doubles.append(c.x)
            doubles.append(c.y)

        cgf = CurvedGeometryFactory(tolerance)
        _CircularString.__init__(self, doubles, cgf, tolerance)


geom._enhance(CircularString)
core.registerTypeMapping(_CircularString, CircularString)
Example #21
0
from org.locationtech.jts.geom import Coordinate
from org.locationtech.jts.geom import Point as _Point
from geoscript import core
import geom


class Point(_Point):
    """
  A Point geometry.

  *coord* is a variable list of x, y, z arguments.

  >>> Point(1,2)
  POINT (1 2)
  """
    def __init__(self, *coord):

        if len(coord) == 1 and isinstance(coord[0], _Point):
            p = coord[0]
        else:
            c = Coordinate(coord[0], coord[1])
            if len(coord) > 2:
                c.z = coord[2]
            p = geom._factory.createPoint(c)

        _Point.__init__(self, p.coordinateSequence, geom._factory)


geom._enhance(Point)
core.registerTypeMapping(_Point, Point)
from org.geotools.geometry.jts import CurvedGeometryFactory
from linestring import LineString
from circularstring import CircularString
from java.lang import Double
from geoscript import core
import geom


class CompoundCurve(_CompoundCurve):
    """
    A CompoundCurve geometry.

    *linestrings* is a variable list of ``LineStrings`` or ``CircularStrings`` arguments.

    >>> CompoundCurve(CircularString([10.0, 10.0], [0.0, 20.0], [-10.0, 10.0]), LineString([-10.0, 10.0], [-10.0, 0.0], [10.0, 0.0], [5.0, 5.0]))
    COMPOUNDCURVE (CIRCULARSTRING (10.0 10.0, 0.0 20.0, -10.0 10.0), (-10.0 10.0, -10.0 0.0, 10.0 0.0, 5.0 5.0))
    """
    def __init__(self, *linestrings):
        tolerance = Double.MAX_VALUE
        if len(linestrings) == 1 and isinstance(linestrings[0],
                                                _CompoundCurve):
            cc = linestrings[0]
            linestrings = cc.components

        cgf = CurvedGeometryFactory(tolerance)
        _CompoundCurve.__init__(self, linestrings, cgf, tolerance)


geom._enhance(CompoundCurve)
core.registerTypeMapping(_CompoundCurve, CompoundCurve)