Beispiel #1
0
    def cursor(self, filter=None, sort=None, hints=None):
        """
    Returns a :class:`Cursor <geoscript.layer.cursor.Cursor>` over the features of the layer.

    *filter* is a optional :class:`Filter <geoscript.filter.Filter>` to constrain the features iterated over.

    *sort* is an optional tuple or ``list`` of tuples that defined the order in
    which features are iterated over. The first value of each tuple is the name
    of a field to sort on. The second value is one of the strings 'ASC' or 
    'DESC', representing ascending and decending sort order respectively. 

    >>> l = Layer()
    >>> from geoscript import geom
    >>> l.add([geom.Point(1,2)])
    >>> l.add([geom.Point(3,4)])
    >>> l.add([geom.Point(5,6)])
    >>> l.add([geom.Point(7,8)])
    >>> l.add([geom.Point(9,10)])
    >>> c = l.cursor()
    >>> f = c.next() 
    >>> f.geom
    POINT (1 2)
    >>> f = c.next() 
    >>> f.geom
    POINT (3 4)
    >>> features = c.read(2)
    >>> len(features)
    2
    >>> features[0].geom
    POINT (5 6)
    >>> features[1].geom
    POINT (7 8)
    >>> features = c.read(2)
    >>> len(features)
    1
    >>> features[0].geom
    POINT (9 10)
    >>> c.close()
    """

        f = Filter(filter) if filter else Filter.PASS
        q = DefaultQuery(self.name, f._filter)
        if sort:
            sort = sort if isinstance(sort, list) else [sort]
            sortBy = []
            ff = _filterFactory
            for s in sort:
                s = s if isinstance(s, tuple) else [s, 'ASC']
                sortBy.append(ff.sort(s[0], SortOrder.valueOf(s[1])))
                q.setSortBy(sortBy)
        if self.proj:
            q.coordinateSystem = self.proj._crs

        if hints is not None:
            q.setHints(Hints(hints))

        fcol = self._source.getFeatures(q)
        #r = self._source.dataStore.getFeatureReader(q,Transaction.AUTO_COMMIT)
        return Cursor(fcol, self)
Beispiel #2
0
  def cursor(self, filter=None, sort=None, hints=None):
    """
    Returns a :class:`Cursor <geoscript.layer.cursor.Cursor>` over the features of the layer.

    *filter* is a optional :class:`Filter <geoscript.filter.Filter>` to constrain the features iterated over.

    *sort* is an optional tuple or ``list`` of tuples that defined the order in
    which features are iterated over. The first value of each tuple is the name
    of a field to sort on. The second value is one of the strings 'ASC' or 
    'DESC', representing ascending and decending sort order respectively. 

    >>> l = Layer()
    >>> from geoscript import geom
    >>> l.add([geom.Point(1,2)])
    >>> l.add([geom.Point(3,4)])
    >>> l.add([geom.Point(5,6)])
    >>> l.add([geom.Point(7,8)])
    >>> l.add([geom.Point(9,10)])
    >>> c = l.cursor()
    >>> f = c.next() 
    >>> f.geom
    POINT (1 2)
    >>> f = c.next() 
    >>> f.geom
    POINT (3 4)
    >>> features = c.read(2)
    >>> len(features)
    2
    >>> features[0].geom
    POINT (5 6)
    >>> features[1].geom
    POINT (7 8)
    >>> features = c.read(2)
    >>> len(features)
    1
    >>> features[0].geom
    POINT (9 10)
    >>> c.close()
    """

    f = Filter(filter) if filter else Filter.PASS
    q = DefaultQuery(self.name, f._filter)
    if sort:
      sort = sort if isinstance(sort, list) else [sort]
      sortBy = [] 
      ff = _filterFactory
      for s in sort: 
        s = s if isinstance(s, tuple) else [s, 'ASC']
        sortBy.append(ff.sort(s[0], SortOrder.valueOf(s[1])))
        q.setSortBy(sortBy)
    if self.proj:
      q.coordinateSystem = self.proj._crs

    if hints is not None:
      q.setHints(Hints(hints))

    fcol = self._source.getFeatures(q)
    #r = self._source.dataStore.getFeatureReader(q,Transaction.AUTO_COMMIT)
    return Cursor(fcol, self)
Beispiel #3
0
  def reproject(self, prj, name=None, chunk=1000):
    """
    Reprojects a layer.

    *prj* is the destination :class:`Projection <geoscript.proj.Projection>` 

    *name* is the optional name as a ``str`` to assign to the resulting reprojected layer.

    This method returns a newly reprojected layer. The new layer is create within the containing workspace of the original layer.

    >>> from geoscript import geom
    >>> l = Layer()
    >>> l.proj = 'epsg:4326'
    >>> l.add([geom.Point(-111, 45.7)])
    >>> 
    >>> l2 = l.reproject('epsg:26912')
    >>> l2.proj.id
    'EPSG:26912'

    >>> [f.geom.round() for f in l2.features()]
    [POINT (500000 5060716)]
    """

    prj = proj.Projection(prj)
    name = name or Layer._newname()

    # reproject the schema
    rschema = self.schema.reproject(prj, name)

    # create the reprojected layer
    rlayer = self.workspace.create(schema=rschema)

    # create a query specifying that feautres should be reprojected
    q = DefaultQuery(self.name, Filter.PASS._filter)
    if self.proj:
      q.coordinateSystem = self.proj._crs
    q.coordinateSystemReproject = prj._crs 

    # loop through features and add to new reprojeced layer
    fit = self._source.getFeatures(q).features()
    try:
      while True:
        features = readFeatures(fit, self._source.getSchema(), chunk)
        if features.isEmpty(): 
          break
  
        rlayer._source.addFeatures(features)
    finally:
      fit.close()
    return rlayer
Beispiel #4
0
    def reproject(self, prj, name=None, chunk=1000):
        """
    Reprojects a layer.

    *prj* is the destination :class:`Projection <geoscript.proj.Projection>` 

    *name* is the optional name as a ``str`` to assign to the resulting reprojected layer.

    This method returns a newly reprojected layer. The new layer is create within the containing workspace of the original layer.

    >>> from geoscript import geom
    >>> l = Layer()
    >>> l.proj = 'epsg:4326'
    >>> l.add([geom.Point(-111, 45.7)])
    >>> 
    >>> l2 = l.reproject('epsg:26912')
    >>> l2.proj.id
    'EPSG:26912'

    >>> [f.geom.round() for f in l2.features()]
    [POINT (500000 5060716)]
    """

        prj = proj.Projection(prj)
        name = name or Layer._newname()

        # reproject the schema
        rschema = self.schema.reproject(prj, name)

        # create the reprojected layer
        rlayer = self.workspace.create(schema=rschema)

        # create a query specifying that feautres should be reprojected
        q = DefaultQuery(self.name, Filter.PASS._filter)
        if self.proj:
            q.coordinateSystem = self.proj._crs
        q.coordinateSystemReproject = prj._crs

        # loop through features and add to new reprojeced layer
        fit = self._source.getFeatures(q).features()
        try:
            while True:
                features = readFeatures(fit, self._source.getSchema(), chunk)
                if features.isEmpty():
                    break

                rlayer._source.addFeatures(features)
        finally:
            fit.close()
        return rlayer
Beispiel #5
0
    def reproject(self, prj, name=None):
        """
    Reprojects a layer.

    *prj* is the destination :class:`Projection <geoscript.proj.Projection>` 

    *name* is the optional name as a ``str`` to assign to the resulting reprojected layer.

    This method returns a newly reprojected layer. The new layer is create within the containing workspace of the original layer.

    >>> from geoscript import geom
    >>> l = Layer()
    >>> l.proj = 'epsg:4326'
    >>> l.add([geom.Point(-111, 45.7)])
    >>> 
    >>> l2 = l.reproject('epsg:26912')
    >>> l2.proj.id
    'EPSG:26912'

    >>> [f.geom for f in l2.features()]
    [POINT (499999.42501775385 5060716.092032814)]
    """

        prj = proj.Projection(prj)
        name = name or Layer._newname()

        # reproject the schema
        rschema = self.schema.reproject(prj, name)

        # create the reprojected layer
        rlayer = self.workspace.create(schema=rschema)

        # create a query specifying that feautres should be reproje`cted
        q = DefaultQuery(self.name, Filter.PASS._filter)
        if self.proj:
            q.coordinateSystem = self.proj._crs
        q.coordinateSystemReproject = prj._crs

        fc = self._source.getFeatures(q)
        i = fc.features()

        # loop through features and add to new reprojeced layer
        while i.hasNext():
            f = feature.Feature(schema=rschema, f=i.next())
            rlayer.add(f)

        fc.close(i)
        return rlayer
Beispiel #6
0
    def reproject(self, prj, name=None):
        """
    Reprojects a layer.

    *prj* is the destination :class:`Projection <geoscript.proj.Projection>` 

    *name* is the optional name as a ``str`` to assign to the resulting reprojected layer.

    This method returns a newly reprojected layer. The new layer is create within the containing workspace of the original layer.

    >>> from geoscript import geom
    >>> l = Layer()
    >>> l.proj = 'epsg:4326'
    >>> l.add([geom.Point(-111, 45.7)])
    >>> 
    >>> l2 = l.reproject('epsg:26912')
    >>> l2.proj.id
    'EPSG:26912'

    >>> [f.geom for f in l2.features()]
    [POINT (499999.42501775385 5060716.092032814)]
    """

        prj = proj.Projection(prj)
        name = name or Layer._newname()

        # reproject the schema
        rschema = self.schema.reproject(prj, name)

        # create the reprojected layer
        rlayer = self.workspace.create(schema=rschema)

        # create a query specifying that feautres should be reproje`cted
        q = DefaultQuery(self.name, Filter.PASS._filter)
        if self.proj:
            q.coordinateSystem = self.proj._crs
        q.coordinateSystemReproject = prj._crs

        fc = self._source.getFeatures(q)
        i = fc.features()

        # loop through features and add to new reprojeced layer
        while i.hasNext():
            f = feature.Feature(schema=rschema, f=i.next())
            rlayer.add(f)

        fc.close(i)
        return rlayer
Beispiel #7
0
    def cursor(self, filter=None):
        """
    Returns a :class:`Cursor <geoscript.layer.cursor.Cursor>` over the features of the layer.

    *filter* is a optional :class:`Filter <geoscript.filter.Filter>` to constrain the features iterated over.

    >>> l = Layer()
    >>> from geoscript import geom
    >>> l.add([geom.Point(1,2)])
    >>> l.add([geom.Point(3,4)])
    >>> l.add([geom.Point(5,6)])
    >>> l.add([geom.Point(7,8)])
    >>> l.add([geom.Point(9,10)])
    >>> c = l.cursor()
    >>> f = c.next() 
    >>> f.geom
    POINT (1 2)
    >>> f = c.next() 
    >>> f.geom
    POINT (3 4)
    >>> features = c.read(2)
    >>> len(features)
    2
    >>> features[0].geom
    POINT (5 6)
    >>> features[1].geom
    POINT (7 8)
    >>> features = c.read(2)
    >>> len(features)
    1
    >>> features[0].geom
    POINT (9 10)
    >>> c.close()
    """

        f = Filter(filter) if filter else Filter.PASS
        q = DefaultQuery(self.name, f._filter)
        if self.proj:
            q.coordinateSystem = self.proj._crs

        r = self._source.dataStore.getFeatureReader(q, Transaction.AUTO_COMMIT)
        return Cursor(r, self)
Beispiel #8
0
    def cursor(self, filter=None):
        """
    Returns a :class:`Cursor <geoscript.layer.cursor.Cursor>` over the features of the layer.

    *filter* is a optional :class:`Filter <geoscript.filter.Filter>` to constrain the features iterated over.

    >>> l = Layer()
    >>> from geoscript import geom
    >>> l.add([geom.Point(1,2)])
    >>> l.add([geom.Point(3,4)])
    >>> l.add([geom.Point(5,6)])
    >>> l.add([geom.Point(7,8)])
    >>> l.add([geom.Point(9,10)])
    >>> c = l.cursor()
    >>> f = c.next() 
    >>> f.geom
    POINT (1 2)
    >>> f = c.next() 
    >>> f.geom
    POINT (3 4)
    >>> features = c.read(2)
    >>> len(features)
    2
    >>> features[0].geom
    POINT (5 6)
    >>> features[1].geom
    POINT (7 8)
    >>> features = c.read(2)
    >>> len(features)
    1
    >>> features[0].geom
    POINT (9 10)
    >>> c.close()
    """

        f = Filter(filter) if filter else Filter.PASS
        q = DefaultQuery(self.name, f._filter)
        if self.proj:
            q.coordinateSystem = self.proj._crs

        r = self._source.dataStore.getFeatureReader(q, Transaction.AUTO_COMMIT)
        return Cursor(r, self)