Skip to content

Commit

Permalink
Added Shapefile Intersect
Browse files Browse the repository at this point in the history
  • Loading branch information
Sieboldianus committed Apr 10, 2018
1 parent aaa025a commit cba2ab2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
4 changes: 3 additions & 1 deletion 00_Config/SortOutAlways.txt
Expand Up @@ -314,4 +314,6 @@ mayfair
hefe
sutro
valencia
brannan
brannan
instadaily
ich
41 changes: 37 additions & 4 deletions generateTagClusters.py
Expand Up @@ -61,10 +61,8 @@
import shapely.geometry as geometry
import pyproj #import Proj, transform
#https://gis.stackexchange.com/questions/127427/transforming-shapely-polygon-and-multipolygon-objects

from shapely.ops import transform
#from shapely.geometry import Polygon
#from shapely.geometry import shape
#from shapely.geometry import Point
from decimal import Decimal

#alternative Shapefile module pure Python
Expand Down Expand Up @@ -150,6 +148,27 @@ def print_store_log(text,end=None):
topicModeling = args.topicModeling
writeCleanedData = args.writeCleanedData
localSaturationCheck = args.localSaturationCheck
shapefileIntersect = True

###SHAPEFILESTUFF###
if shapefileIntersect:
from shapely.geometry import Polygon
from shapely.geometry import shape
from shapely.geometry import Point
PShape = fiona.open("D:/03_EvaVGI/01_Daten/2018-02-20_NationalPark_Berchtesgarden_Nicola/nationalpark_berchtesgarden_osm.shp")

######Single Polygon:######
first = PShape.next()
print("Loaded Shapefile with " + str(len(first['geometry']['coordinates'][0])) + " Vertices.") # (GeoJSON format)
shp_geom = shape(first['geometry']) #shape(first)

######Multipolygon:######
#vcount = PShape.next()['geometry']['coordinates'] #needed for count of vertices
#geom = MultiPolygon([shape(pol['geometry']) for pol in PShape])
#shp_geom = geom
#print("Loaded Shapefile with Vertices ", sum([len(poly[0]) for poly in vcount])) # (GeoJSON format)
###END SHAPEFILESTUFF###

if args.EPSG is None:
overrideCRS = None
else:
Expand Down Expand Up @@ -621,7 +640,21 @@ def is_number(s):
photo_latitude = Decimal(item[2]) #guid
photo_longitude = Decimal(item[3]) #guid
setLatLngBounds(photo_latitude,photo_longitude)
photo_locID = str(photo_latitude) + ':' + str(photo_longitude) #create loc_id from lat/lng
photo_locID = str(photo_latitude) + ':' + str(photo_longitude) #create loc_id from lat/lng
#assign lat/lng coordinates from dict
if shapefileIntersect:
#skip all outside shapefile
if photo_locID in shapeFileExcludelocIDhash:
skippedCount += 1
continue
if not photo_locID in shapeFileIncludedlocIDhash:
LngLatPoint = Point(photo_longitude, photo_latitude)
if not LngLatPoint.within(shp_geom):
skippedCount += 1
shapeFileExcludelocIDhash.add(photo_locID)
continue
else:
shapeFileIncludedlocIDhash.add(photo_locID)
#empty for Instagram:
photo_mTags = ""
photo_dateTaken = ""
Expand Down

0 comments on commit cba2ab2

Please sign in to comment.