Last active
January 4, 2023 09:28
-
-
Save kkprakasa/966fe6baa8193efa9beb3f651afab827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
geofencing alfamart | |
# uri toko | |
dict(zip([ i.select('span')[15].text for i in soup.select('div[jstcache="206"]')],[ i.select('span')[0].text for i in soup.select('div[jstcache="206"]')])) | |
dict(zip([ i.select('span')[15].text for i in soup.select('div[jstcache="206"]')],list(zip([ i.find('a')['href'] for i in soup.select('div[jstcache="206"]')],[ i.select('span')[0].text for i in soup.select('div[jstcache="206"]')])))) | |
# shape | |
import shapefile | |
shape = shapefile.Reader("my_shapefile.shp") | |
#first feature of the shapefile | |
feature = shape.shapeRecords()[0] | |
first = feature.shape.__geo_interface__ | |
print first # (GeoJSON format) | |
from shapely.geometry import Point | |
from shapely.geometry.polygon import Polygon | |
lons_lats_vect = np.column_stack((lons_vect, lats_vect)) # Reshape coordinates | |
polygon = Polygon(lons_lats_vect) # create polygon | |
point = Point(y,x) # create point | |
print(polygon.contains(point)) # check if polygon contains point | |
print(point.within(polygon)) # check if a point is in the polygon | |
# PENTING | |
# regex ambil koordinat (?<=3d)(\-.*)(?=\!) | |
# | |
import re | |
str.split(re.search('(?<=3d)(.*)(?=\!)',test).group(1),'!4d') | |
for data in aa: | |
data.update({'koord':str.split(re.search('(?<=3d)(.*)(?=\!)',data['uri']).group(1),'!4d')}) | |
point = Point(tuple([float(i) for i in str.split(re.search('(?<=3d)(.*)(?=\!)',test).group(1),'!4d')])) | |
import shapefile | |
from shapely.geometry import Point | |
from shapely.geometry.polygon import Polygon | |
shape = shapefile.Reader("my_shapefile.shp") | |
feature = shape.shapeRecords()[0] | |
first = feature.shape.__geo_interface__ | |
polygon = Polygon(first['coordinates'][0]) | |
# multi | |
import shapefile | |
from shapely.geometry.polygon import Polygon | |
from shapely.geometry import Point # Point class | |
from shapely.geometry import shape # shape() is a function to convert geo objects through the interface | |
shp = shapefile.Reader("/natural-earth-vector-master/10m_cultural/ne_10m_admin_0_countries_lakes.shp") | |
all_shapes = shp.shapes() # get all the polygons | |
all_records = shp.records() | |
for i in range(len(all_shapes)): | |
boundary = all_shapes[i] | |
if Point(point).within(shape(boundary)): # | |
name = all_records[i][3] | |
print(name) | |
for i in range(len(shp.shapes())): | |
Point(-6.802824545999954,110.83657753300008).distance(shape(shp.shapes()[i])) | |
United States of America | |
def cek_poin(a,b): | |
for i in range(len(all_shapes)): | |
boundary = all_shapes[i] | |
if Point(a,b).within(shape(boundary)): # | |
name = all_records[i][3] | |
print(name) | |
point = Point(110.840721927412,-6.81054739189549) | |
# yg 110 didepan, yg -6 dibelakang | |
point = Point(106.890993,-6.1842052) | |
for i in range(len(all_shapes)): | |
bund = all_shapes[i] | |
if point.within(shape(bund)): | |
name = all_records[i][5] | |
print(name) | |
for j in a: | |
try: | |
point = Point(float(j['koord'][1]),float(j['koord'][0])) | |
for i in range(len(all_shapes)): | |
bund = all_shapes[i] | |
if point.within(shape(bund)): | |
z={} | |
z['id_Provinsi'] = all_records[i][2] | |
z['Provinsi'] = all_records[i][3] | |
z['id_kabkota'] = all_records[i][8] | |
z['kabkota'] = all_records[i][10] | |
z['id_kec'] = all_records[i][9] | |
z['kec'] = all_records[i][4] | |
z['id_desa'] = all_records[i][7] | |
z['desa'] = all_records[i][5] | |
j.update(z) | |
print(z) | |
except: | |
continue | |
point = Point(-6.2251843,106.8922647) | |
for i in range(len(all_shapes)): | |
bund = all_shapes[i] | |
if point.within(shape(bund)): | |
name = all_records[i][9] | |
print(name) | |
x = [] | |
for j in point: | |
try: | |
for i in range(len(all_shape)): | |
bund = all_shape[i] | |
if Point(j).within(shape(bund)): | |
z={} | |
z['id_Provinsi'] = all_records[i][2] | |
z['Provinsi'] = all_records[i][3] | |
z['id_kabkota'] = all_records[i][8] | |
z['kabkota'] = all_records[i][10] | |
z['id_kec'] = all_records[i][9] | |
z['kec'] = all_records[i][4] | |
z['id_desa'] = all_records[i][7] | |
z['desa'] = all_records[i][5] | |
z['koord'] = j | |
x.append(z) | |
print(z) | |
except: | |
continue | |
## KOPI | |
for j in a: | |
try: | |
point = Point(float(j['koord'][1]),float(j['koord'][0])) | |
for i in range(len(all_shapes)): | |
bund = all_shapes[i] | |
if point.within(shape(bund)): | |
z={} | |
z['id_Provinsi'] = all_records[i][1] | |
z['Provinsi'] = all_records[i][3] | |
z['id_kabkota'] = all_records[i][6] | |
z['kabkota'] = all_records[i][4] | |
j.update(z) | |
print(z) | |
except: | |
continue | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment