| Name | gdalwrap JSON |
| Version |
1.1.1
JSON |
| download |
| home_page | |
| Summary | GDAL python bindings wrapper and helper functions. |
| upload_time | 2023-10-07 03:16:09 |
| maintainer | |
| docs_url | None |
| author | |
| requires_python | >=3.1 |
| license | |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
After initial excitement about GDAL python bindings possibilities I realized something was wrong, as my code could not work as expected. Fortunately checked that there’s nothing wrong about it but [Python Gotchas](https://gdal.org/api/python_gotchas.html)
Summing-up: Python gdal/ogr objects are pointers to [SWIG](https://www.swig.org/) objects and these pointers will be collected by Python's garbage collector earlier than expected in code execution. In practice the problem is it makes writing code tied to a very monolithic approach.
After trying alternatives to make it more usable for Python I eventually found a way that's working until now: keeping these pointers busy, allocated. In this case this is done by having key elements (datasources e.g.) 'grabbed' by class objects.
This repository is Beta/under construction and contains some basic features and some processing tools. I will use it to keep adding functionality and helper functions for my recurring tasks while working with GIS files.
Usage can be checked in the [examples.py](https://github.com/Rodrigo-NH/gdalwrap/blob/main/examples/examples.py) file
[Recipe](https://gist.github.com/Rodrigo-NH/94d1fe07646052ad32133824c85b4221) to get all gdal/gdal bindings parts installed and configured in Windows
## Installation
pip install --user gdalwrap
## Classes/commands
Core commands (file core.py)
The gdalwrap idea is to wrap OGR classes into Python classes, circumventing some of the Python gotchas. Respecting OGR higther classes hierarchy (datasource/layers/features/geometries) while permitting easy access to native OGR objects. Considering python is 'just' making reference to OGR object pointers, it's possible to work directly with the OGR objects (using the bindings directly) without breaking the code logic constructed with gdalwrap.
Example:
```python
temps = Datasource(geopackagepath, Action="open rw") # Open a file
print(temps.datasource) # Native OGR datasource object
newlayer = temps.Newlayer('polygons_1', '4326', Type='polygon') # Create a new layer
existinglayer = temps.getlayer('somelayer') # Pick some existing layer
print(newlayer.layer) # Native OGR layer object
print(existinglayer.layer) # Native OGR layer object
somefeature = existinglayer.getfeature(0) # Random access by FID
print(somefeature.feature) # Native OGR feature object
iter = existinglayer.iterfeatures() # Feature iterator (wraps OGR '.GetNextFeature())'
for feature in iter:
fg = feature.getgeom()
print(fg.geom) # Native OGR geometry object
```
You can check the examples.py for usage until a better README arises.
## Tools
Some useful tools. (file tools.py)
**Method splithalf:**
```splithalf(<geom>)``` -> Split geom in half and returns a list with resulting geoms
**Method layerclip:**
Clips features in a layer and returns resulting feature list. Replicates attribute table values. Doesn't change input layer.
```layerclip(<layer>, <clipgeom>)``` -> Returns list of output features
layer -> The input layer to be clipped
clipgeom -> The geom used as clip mask
**Class Layergrid:**
Creates a grid with the total extent of a given layer. X and Y steps in current map units or total number of tiles. Inherits srs from layer. User inputs 'Xstep' and 'Ystep' will be adjusted (changed) to match layer's extent exactly.
```Layergrid(<layer>, <Xstep>, <Ystep>, [Type='mapunits'])```
Type=
'mapunits' -> Default. Xstep and Ytep in map units
'tilenumbers' -> Xstep and Ytep as total number of tiles (e.g. Xstep=4, Ystep=4 for a 16 tiles grid)
*Methods:*
```.getgrid()``` -> Get a list with all grid geoms
```.gridindex()``` -> Get a string list with grid index in the format "xi_yi"
```.getsrs()``` -> Get grid's associated SRS
**Method splitrings:**
Removes rings from feature but keeping overall aspect (a polygon with one ring will be transformed to two polygons respecting the empty space of the ring). Returns a list of features. replicates source attributes.
```splitrings(<feature>)``` -> Returns a list of resulting features

**Method splitvertices:**
Split features based on max number of vertices threshold.
```splitvertices(<feature>, <threshold>)``` -> Returns a list of resulting features
Raw data
{
"_id": null,
"home_page": "",
"name": "gdalwrap",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.1",
"maintainer_email": "",
"keywords": "",
"author": "",
"author_email": "Rodrigo Nascimento Hernandez <rodrigomdev@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a4/eb/37a1e320dcf92466d68c1a032c140fca29cceb4347fea22a2866d04b49f4/gdalwrap-1.1.1.tar.gz",
"platform": null,
"description": "After initial excitement about GDAL python bindings possibilities I realized something was wrong, as my code could not work as expected. Fortunately checked that there\u2019s nothing wrong about it but [Python Gotchas](https://gdal.org/api/python_gotchas.html) \nSumming-up: Python gdal/ogr objects are pointers to [SWIG](https://www.swig.org/) objects and these pointers will be collected by Python's garbage collector earlier than expected in code execution. In practice the problem is it makes writing code tied to a very monolithic approach. \nAfter trying alternatives to make it more usable for Python I eventually found a way that's working until now: keeping these pointers busy, allocated. In this case this is done by having key elements (datasources e.g.) 'grabbed' by class objects. \nThis repository is Beta/under construction and contains some basic features and some processing tools. I will use it to keep adding functionality and helper functions for my recurring tasks while working with GIS files. \nUsage can be checked in the [examples.py](https://github.com/Rodrigo-NH/gdalwrap/blob/main/examples/examples.py) file \n[Recipe](https://gist.github.com/Rodrigo-NH/94d1fe07646052ad32133824c85b4221) to get all gdal/gdal bindings parts installed and configured in Windows \n\n## Installation \npip install --user gdalwrap\n## Classes/commands\nCore commands (file core.py) \n\nThe gdalwrap idea is to wrap OGR classes into Python classes, circumventing some of the Python gotchas. Respecting OGR higther classes hierarchy (datasource/layers/features/geometries) while permitting easy access to native OGR objects. Considering python is 'just' making reference to OGR object pointers, it's possible to work directly with the OGR objects (using the bindings directly) without breaking the code logic constructed with gdalwrap. \n\nExample: \n\n```python\ntemps = Datasource(geopackagepath, Action=\"open rw\") # Open a file\nprint(temps.datasource) # Native OGR datasource object\nnewlayer = temps.Newlayer('polygons_1', '4326', Type='polygon') # Create a new layer\nexistinglayer = temps.getlayer('somelayer') # Pick some existing layer\nprint(newlayer.layer) # Native OGR layer object\nprint(existinglayer.layer) # Native OGR layer object\nsomefeature = existinglayer.getfeature(0) # Random access by FID\nprint(somefeature.feature) # Native OGR feature object\n\niter = existinglayer.iterfeatures() # Feature iterator (wraps OGR '.GetNextFeature())'\nfor feature in iter:\n\tfg = feature.getgeom()\n\tprint(fg.geom) # Native OGR geometry object\n```\nYou can check the examples.py for usage until a better README arises.\n\n\n## Tools\nSome useful tools. (file tools.py)\n\n\n**Method splithalf:** \n\n\n```splithalf(<geom>)``` -> Split geom in half and returns a list with resulting geoms\n\n\n**Method layerclip:**\n\nClips features in a layer and returns resulting feature list. Replicates attribute table values. Doesn't change input layer. \n\n```layerclip(<layer>, <clipgeom>)``` -> Returns list of output features \n\nlayer -> The input layer to be clipped \n\nclipgeom -> The geom used as clip mask\n\n\n**Class Layergrid:** \n\nCreates a grid with the total extent of a given layer. X and Y steps in current map units or total number of tiles. Inherits srs from layer. User inputs 'Xstep' and 'Ystep' will be adjusted (changed) to match layer's extent exactly.\n\n```Layergrid(<layer>, <Xstep>, <Ystep>, [Type='mapunits'])``` \n\nType= \n'mapunits' -> Default. Xstep and Ytep in map units \n'tilenumbers' -> Xstep and Ytep as total number of tiles (e.g. Xstep=4, Ystep=4 for a 16 tiles grid)\n\n*Methods:* \n\n```.getgrid()``` -> Get a list with all grid geoms \n\n\n```.gridindex()``` -> Get a string list with grid index in the format \"xi_yi\" \n\n```.getsrs()``` -> Get grid's associated SRS\n\n**Method splitrings:** \n\nRemoves rings from feature but keeping overall aspect (a polygon with one ring will be transformed to two polygons respecting the empty space of the ring). Returns a list of features. replicates source attributes. \n\n```splitrings(<feature>)``` -> Returns a list of resulting features\n\n \n\n**Method splitvertices:** \n\nSplit features based on max number of vertices threshold. \n\n```splitvertices(<feature>, <threshold>)``` -> Returns a list of resulting features \n\n \n",
"bugtrack_url": null,
"license": "",
"summary": "GDAL python bindings wrapper and helper functions.",
"version": "1.1.1",
"project_urls": {
"Bug Tracker": "https://github.com/Rodrigo-NH/gdalwrap/issues",
"Homepage": "https://github.com/Rodrigo-NH/gdalwrap"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c858205db7add90084e88b0d8bcd1eb86e380cfd07d8fa9b7b281dcf78e75975",
"md5": "b60c623c52bb60cd96590d3db08d592a",
"sha256": "0204f8098f1c8c29843378ee5c79861c7c1e2c79fd4890eb20d4446e990bd215"
},
"downloads": -1,
"filename": "gdalwrap-1.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b60c623c52bb60cd96590d3db08d592a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.1",
"size": 11755,
"upload_time": "2023-10-07T03:16:07",
"upload_time_iso_8601": "2023-10-07T03:16:07.471997Z",
"url": "https://files.pythonhosted.org/packages/c8/58/205db7add90084e88b0d8bcd1eb86e380cfd07d8fa9b7b281dcf78e75975/gdalwrap-1.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a4eb37a1e320dcf92466d68c1a032c140fca29cceb4347fea22a2866d04b49f4",
"md5": "e84f70fea1aeb1042b651d7b5db1af5d",
"sha256": "69a0e5757e9cedeea15eaf74ac51bde6ccaf698bedc3a8908df9972d871a5a36"
},
"downloads": -1,
"filename": "gdalwrap-1.1.1.tar.gz",
"has_sig": false,
"md5_digest": "e84f70fea1aeb1042b651d7b5db1af5d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.1",
"size": 16079,
"upload_time": "2023-10-07T03:16:09",
"upload_time_iso_8601": "2023-10-07T03:16:09.056597Z",
"url": "https://files.pythonhosted.org/packages/a4/eb/37a1e320dcf92466d68c1a032c140fca29cceb4347fea22a2866d04b49f4/gdalwrap-1.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-07 03:16:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Rodrigo-NH",
"github_project": "gdalwrap",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "gdalwrap"
}