5

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?)

asked Oct 20, 2015 at 13:11
3
  • 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? Commented 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. Commented Oct 20, 2015 at 13:42
  • @Kersten, I have a preference for not using GDAL, but either way would be a big relief. Commented Oct 20, 2015 at 13:57

2 Answers 2

9

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/

answered Oct 21, 2015 at 1:48
1
  • 1
    One 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. Commented Sep 10, 2021 at 22:50
0

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

answered Oct 21, 2015 at 0:44
3
  • is shp2pgsql a python package? I can't find anything about it. Commented Oct 21, 2015 at 1:13
  • no its not python package it comes with postgreSQL. bostongis.com/pgsql2shp_shp2pgsql_quickguide.bqg Commented 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. Commented Oct 21, 2015 at 1:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.