Using Shapefile Data to Define a Neighborhood for Longitude / Latitude

I am trying to determine neighborhoods for a location based on freely published Shapefile Zillow data.

I don’t know anything about the Shapefile format, and I have some problems finding trainers online, but I mainly want to use latitude / longitude pairs and run it against Shapefile data to determine the corresponding neighborhoods (s).

Can someone point me in the right direction? Not even sure where to start.

This is where I captured the Shapefiles: http://www.zillow.com/howto/api/neighborhood-boundaries.htm

+6
php geolocation shapefile
source share
2 answers

Here is an example of using PostGIS, spatial extensions for postgresql. Similar extensions exist for mysql, oracle, mssql, sqlite and, no doubt, other databases. PostGIS must be installed for this to work.

First you must convert the shapefile to sql file:

fmark@fmark-laptop :~$ shp2pgsql -c Desktop/zillow/ZillowNeighborhoods-AK.shp zillowak > Desktop/zillow/ZillowNeighborhoods-AK.sql Shapefile type: Polygon Postgis type: MULTIPOLYGON[2] 

Then run sql in the database (the "gis" database in this case) to convert the sql file to a spatially resolved table:

 fmark@fmark-laptop :~$ psql -d gis -f Desktop/zillow/ZillowNeighborhoods-AK.sql SET BEGIN ... COMMIT 

At this point, you probably want to create a spatial index as you are going to make a spatial query:

 fmark@fmark-laptop :~$ psql -d gis psql (8.4.2) Type "help" for help. gis=# CREATE INDEX idx_neighborhoods ON zillowak USING gist(the_geom); CREATE INDEX gis-# \q 

Now, if you have lat / long (in this example -149.309W, 60.985S), you can find what area it is in: fmark @ fmark-laptop: ~ $ psql -d gis psql (8.4.2) Enter "help" for reference.

 gis=# select gid, state, county, city, name, regionid from zillowak WHERE ST_CONTAINS(the_geom, GeomFromText('POINT(-149.309 60.985)', -1)); gid | state | county | city | name | regionid -----+-------+-----------+-----------+---------------+---------- 29 | AK | Anchorage | Anchorage | Turnagain Arm | 275783 (1 row) gis=# \q fmark@fmark-laptop :~$ 

This last step can obviously be made from PHP with a simple request.

+9
source share

If you have not yet received an answer to this topic, the method in which you propose is not the most effective mechanism. I will try to come up with an idea of ​​how you can do this in a more efficient way.

Start by importing your shapefile into a GeoSpatial database / datastore.

The lat / lon comparison pattern can still be used, but it will only cause more work for you. Geospatial databases / datastores provide functions for comparing geometries (point, line, polygon). Instead of using latitude and longitude, all types of geometry are stored in a single column of geometry. The functions then allow you to compare distance, size, overlap, intersection, and other comparisons.

How is a shapefile converted?

A form file is a set of tabular data, the name of the neighborhood and additional fields and a way to map these records to a spatially represented location. This is a geospatial file grouping database. The comparison that comes to mind is someone using access as a database compared to a traditional server database. Tools / libraries are available that transform the shapefile into a geospatial database. You can find more information by doing a GDAL search.

Hope this was helpful.

+3
source share

All Articles