Continuation of the last time http://qiita.com/motokazu/items/aaa5970ab34044237cc7
Last time, I drew a circle with a radius from a specific point and generated a point in it, but if you want to generate it only in a certain area, you can not use a circle.
So, use the Shape file of National Land Numerical Information to generate points in Tokyo.
After opening the Download Page, select JPGIS and select "Administrative Area"-> "Tokyo", the latest status Select 2015. Fill out the questionnaire and download.
Try opening the shapefile with QGIS
Tokyo is displayed!
Use this shapefile to make dots in Tokyo. As a processed image,
Read the shape file and make it usable Please refer to here. http://stackoverflow.com/questions/7861196/check-if-a-geopoint-with-latitude-and-longitude-is-within-a-shapefile
First of all, install and use Use fiona to read Shapefiles
$ pip install shapely
$ pip install fiona
Load the library
# shape
import fiona
from shapely.geometry import Point,asShape
Extract the shape file and check if the points indicated by Latitude and Longitude are in the shape file.
with fiona.open(shapefile) as fiona_collection:
shapefile_record = fiona_collection.next()
shape = asShape(shapefile_record['geometry'])
geolat = fake.geo_coordinate(center=centerlat , radius=latradius)
geolong = fake.geo_coordinate(center=centerlong, radius=longradius)
point = Point(geolong, geolat)
if shape.contains(point):
If you think that contains isn't True at all ... because the shapefile is made up of multiple polygons and fiona_collection.next () is fetching only one partition ... I'm sure.
With reference to this, multiple polygons are fused. That helps a lot! https://sites.google.com/site/qgisnoiriguchi/vector01/09
Combine using QGIS. Select the menu "Vector"-> "Spatial Calculation Tool"-> "Fusion"
Select the shape to generate, OK
Became one!
Try to generate points using this shapefile Apparently the number of contains that are True has changed.
Click here for the final code https://gist.github.com/motokazu/a1cb634aa0d6726039bd
Usage example
$ python genpointsbygeo.my.py --shapefile Tokyo.shp --samples 100 --radius 50000
Recommended Posts