Пример #1
0
 def test_ogr_add_geometry(self):
     ds = gdal_create_dataset('Memory', 'test',
                              gdal_type=gdal.OF_VECTOR)
     lyr = georef.ogr_create_layer(ds, 'test', geom_type=ogr.wkbPoint,
                                   fields=[('test', ogr.OFTReal)])
     point = ogr.Geometry(ogr.wkbPoint)
     point.AddPoint(1198054.34, 648493.09)
     georef.ogr_add_geometry(lyr, point, [42.42])
Пример #2
0
 def test_ogr_add_geometry(self):
     ds = wradlib.io.gdal_create_dataset("Memory", "test", gdal_type=gdal.OF_VECTOR)
     lyr = georef.ogr_create_layer(
         ds, "test", geom_type=ogr.wkbPoint, fields=[("test", ogr.OFTReal)]
     )
     point = ogr.Geometry(ogr.wkbPoint)
     point.AddPoint(1198054.34, 648493.09)
     georef.ogr_add_geometry(lyr, point, [42.42])
Пример #3
0
    def _create_dst_features(self, dst, trg, **kwargs):
        """ Create needed OGR.Features in dst OGR.Layer

        Parameters
        ----------
        dst : OGR.Layer
            destination layer
        trg : OGR.Geometry
            target polygon
        """
        # TODO: kwargs necessary?

        # claim and reset source ogr layer
        layer = self.src.ds.GetLayerByName('src')
        layer.ResetReading()

        # if given, we apply a buffer value to the target polygon filter
        trg_index = trg.GetField('index')
        trg = trg.GetGeometryRef()
        trg = trg.Buffer(self._buffer)
        layer.SetSpatialFilter(trg)

        # iterate over layer features
        for ogr_src in layer:
            geom = ogr_src.GetGeometryRef()

            # calculate intersection, if not fully contained
            if not trg.Contains(geom):
                geom = trg.Intersection(geom)

            # checking GeometryCollection, convert to only Polygons,
            #  Multipolygons
            if geom.GetGeometryType() in [7]:
                geocol = georef.ogr_geocol_to_numpy(geom)
                geom = georef.numpy_to_ogr(geocol, 'MultiPolygon')

            # only geometries containing points
            if geom.IsEmpty():
                continue

            if geom.GetGeometryType() in [3, 6, 12]:
                idx = ogr_src.GetField('index')
                georef.ogr_add_geometry(dst, geom, [idx, trg_index])
Пример #4
0
    def _create_dst_features(self, dst, trg, **kwargs):
        """ Create needed OGR.Features in dst OGR.Layer

        Parameters
        ----------
        dst : OGR.Layer
            destination layer
        trg : OGR.Geometry
            target polygon
        """
        # TODO: kwargs necessary?

        # claim and reset source ogr layer
        layer = self.src.ds.GetLayerByName('src')
        layer.ResetReading()

        # if given, we apply a buffer value to the target polygon filter
        trg_index = trg.GetField('index')
        trg = trg.GetGeometryRef()
        trg = trg.Buffer(self._buffer)
        layer.SetSpatialFilter(trg)

        feat_cnt = layer.GetFeatureCount()

        if feat_cnt:
            [
                georef.ogr_add_geometry(dst, ogr_src.GetGeometryRef(),
                                        [ogr_src.GetField('index'), trg_index])
                for ogr_src in layer
            ]
        else:
            layer.SetSpatialFilter(None)
            src_pts = np.array(
                [ogr_src.GetGeometryRef().GetPoint_2D(0) for ogr_src in layer])
            centroid = georef.get_centroid(trg)
            tree = cKDTree(src_pts)
            distnext, ixnext = tree.query([centroid[0], centroid[1]], k=1)
            feat = layer.GetFeature(ixnext)
            georef.ogr_add_geometry(dst, feat.GetGeometryRef(),
                                    [feat.GetField('index'), trg_index])