[Qgis-user] python(3) script to calculate latitude longitude values from (ESRI) shape file

Nicolas Cadieux njacadieux.gitlab at gmail.com
Wed Apr 21 18:16:22 PDT 2021


Hi,

Users of this group will give you good information on the QGIS Python api.  You can use that.

Another way is to use the python Shapely library.  Using the object.bounds method, you will have you xy min and max coordinate.  If you use the geopandas library, you can use he same shapely method but use the power on the pandas dataframe.  Of course, you can also make a vector query in QGIS and add the boundaries limite in a new field.

https://shapely.readthedocs.io/en/stable/manual.html?highlight=bound#object.bounds

You also achieve the same goal using Gdal.  This page is full of code and will give you 99% of what you need.

https://pcjericks.github.io/py-gdalogr-cookbook/geometry.html#calculate-envelope-of-a-geometry


Nicolas Cadieux
https://gitlab.com/njacadieux

> Le 21 avr. 2021 à 16:42, wxgis <thinjogger at gmail.com> a écrit :
> 
> Hi - 
> Wondering if there is existing Python(3) script code that can take an (ESRI)
> shape file as input and then calculate latitude/longitude/elevation values
> for country boundaries.  For example, if the input file is a SHP file for
> France, the output would be the lat/lon/elevation values for the country
> boundaries.  I am quite new to QGIS, looking at version 3.18 (so only know
> about ESRI shape files, maybe there are other types of SHP files?), and read
> that in QGIS  I can edit the attribute table for a given layer and add
> latitude/longitude attributes, but I am hoping to this more
> programmatically, using the QGIS Python console.  I gladly welcome any ideas
> on this.
> 
> TIA,
> Steve
> 
> 
> 
> --
> Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-User-f4125267.html
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210421/146ce08d/attachment.html>


More information about the Qgis-user mailing list