I'm aware that there are several similar questions already but I have been searching for days and not been able to solve my problem:
All solutions I've found require GDAL, which I have not been able to install (even doing all the environment variables tweaking etc.) except by using OSGEO4W, which allows me to use osgeo, but only in its own shell, rather than in the shell I use for everything else.
I have the country shapefiles, I have the shapely package. Is there a way to do this without GDAL? (or as an alternative, an easy way to get GDAL packages in my own shell?)
-
Can you please edit your post to a single question? What do you prefer: installing/importing GDAL or intersecting country shapefiles with GPS coordinates without using GDAL?Kersten– Kersten2015年10月20日 13:36:18 +00:00Commented Oct 20, 2015 at 13:36
-
Study OSGeo4W.bat and see how it sets paths and some environment parameters. That is a bit tricky because the first batch file is calling a bunch of other ones but you can also check the end result with "PATH" and "SET" from your OSGeo4W shell. Then set the same things in your own shell.user30184– user301842015年10月20日 13:42:46 +00:00Commented Oct 20, 2015 at 13:42
-
@Kersten, I have a preference for not using GDAL, but either way would be a big relief.Alexis Eggermont– Alexis Eggermont2015年10月20日 13:57:12 +00:00Commented Oct 20, 2015 at 13:57
2 Answers 2
I finally found what I was looking for: a package called reverse_geocode. It can be installed with pip.
>>>> import reverse_geocoder
>>>> coordinates = (-37.81, 144.96), (31.76, 35.21)
>>>> reverse_geocode.search(coordinates)
[{'city': 'Melbourne', 'code': 'AU', 'country': 'Australia'},
{'city': 'Jerusalem', 'code': 'IL', 'country': 'Israel'}]
Information about the function can be found here: https://pypi.org/project/reverse_geocoder/
-
1One concern I have with this is that it looks like
reverse_geocode.search()
gives you the nearest city (and information about that city) to a coordinate, not information about the coordinate itself. So if your coordinate is near the border of a country, it might select a city across the border and say your coordinate is in the wrong country. For example, this location in Egypt(29.599042, 34.864505)
shows up as Eilat, Israel.bobpaul– bobpaul2021年09月10日 22:50:17 +00:00Commented Sep 10, 2021 at 22:50
you can user shp2pgsql to convert shape file to PostgreSQL table
example :shp2pgsql -a -s 4326 -D \"#{shapeFileName}\" #{tableName} | psql -h #{host} -U #{username} #{database}
This will create postgresTable which would have a geometry column and other columns such as name of county, etc. So each polygon is store as different row.
you can query using http://postgis.net/docs/manual-1.4/ST_Contains.html to check if point is present in polygon and fetch all the rows
-
is shp2pgsql a python package? I can't find anything about it.Alexis Eggermont– Alexis Eggermont2015年10月21日 01:13:34 +00:00Commented Oct 21, 2015 at 1:13
-
no its not python package it comes with postgreSQL. bostongis.com/pgsql2shp_shp2pgsql_quickguide.bqgNikhil Murarka– Nikhil Murarka2015年10月21日 01:29:33 +00:00Commented Oct 21, 2015 at 1:29
-
Thanks. I'd really love a solution that just uses python as I'm not familiar with postgreSQL, but if there isn't one I'll do this.Alexis Eggermont– Alexis Eggermont2015年10月21日 01:40:20 +00:00Commented Oct 21, 2015 at 1:40