Commit 4092eb5a authored by Manggar Mahardhika's avatar Manggar Mahardhika

push

parent 87e39c3b
...@@ -5,5 +5,13 @@ from . import views ...@@ -5,5 +5,13 @@ from . import views
app_name = 'api' app_name = 'api'
urlpatterns = [ urlpatterns = [
path('search_auto', views.search_auto, name='search') path('search_auto', views.search_auto, name='search'),
path('tuplah', views.tuplah, name='tuplah'),
path('building', views.building, name='building'),
path('jalan', views.jalan, name='jalan'),
path('sungai', views.sungai, name='sungai'),
path('edit', views.editpoly, name='edit'),
path('validatedit', views.validatedit, name='validatedit'),
path('hapus', views.hapus, name='hapus'),
path('hasilsearch', views.hasilsearch, name='ressearch')
] ]
\ No newline at end of file
...@@ -16,4 +16,145 @@ def search_auto(request): ...@@ -16,4 +16,145 @@ def search_auto(request):
all = desa.fetchall() all = desa.fetchall()
data = {'nama_des':all} data = {'nama_des':all}
return Response(data) return Response(data)
\ No newline at end of file
@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def tuplah(request):
with conn.cursor() as desa:
desa.execute(f"SELECT json_build_object('type', 'Feature', 'legend', a.legenda,'geometry', ST_AsGeoJSON( st_intersection(a.geom, b.geom):: geometry) :: json) from geo_tuplah a, geo_prov_kab b")
all = desa.fetchall()
data = {'tuplah':all}
return Response(data)
@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def building(request):
if request.method == 'GET':
wetan = request.GET.get("wetan")
kulon = request.GET.get("kulon")
lor = request.GET.get("lor")
kidul = request.GET.get("kidul")
# lat = request.GET.get("lat")
# lng = request.GET.get("lng")
# kulon lor, wetan lor, wetan kidul, kulon kidul, kulon lor
with conn.cursor() as buldings:
buldings.execute("SELECT json_build_object('type', 'Feature', 'properties', (id, name, information, 'gen'), 'administrasi',(address_1, address_2, address_3, provinsi, 'no'), 'geometry', ST_AsGeoJSON(geom :: geometry) :: json) FROM geo_bangunan WHERE st_intersects(geom,'SRID=0;POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))')"% (kulon, lor, wetan, lor, wetan, kidul, kulon, kidul, kulon, lor))
prov_res = buldings.fetchall()
polbang = []
for i in prov_res:
i[0]['properties']['f2'] = i[0]['properties']['f2'].replace("'"," ")
polbang.append(i[0])
data = {'gen':prov_res}
return Response(data)
@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def jalan(request):
if request.method == 'GET':
wetan = request.GET.get("wetan")
kulon = request.GET.get("kulon")
lor = request.GET.get("lor")
kidul = request.GET.get("kidul")
# lat = request.GET.get("lat")
# lng = request.GET.get("lng")
# kulon lor, wetan lor, wetan kidul, kulon kidul, kulon lor
with conn.cursor() as jalan:
jalan.execute("SELECT json_build_object ('type', 'Feature', 'properties', ( id, namrjl ), 'geometry', ST_AsGeoJSON ( st_intersection(geom, 'SRID=4326;POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))') :: geometry ) :: json ) FROM geo_jalan WHERE st_intersects(geom,'SRID=4326;POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))')"% (kulon, lor, wetan, lor, wetan, kidul, kulon, kidul, kulon, lor, kulon, lor, wetan, lor, wetan, kidul, kulon, kidul, kulon, lor))
prov_res = jalan.fetchall()
data = {'gen':prov_res}
return Response(data)
@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def sungai(request):
if request.method == 'GET':
wetan = request.GET.get("wetan")
kulon = request.GET.get("kulon")
lor = request.GET.get("lor")
kidul = request.GET.get("kidul")
# lat = request.GET.get("lat")
# lng = request.GET.get("lng")
# kulon lor, wetan lor, wetan kidul, kulon kidul, kulon lor
with conn.cursor() as sungai:
sungai.execute("SELECT json_build_object ('type', 'Feature', 'properties', ( a.id, a.namobj ), 'geometry', ST_AsGeoJSON ( st_intersection(a.geom, b.geom) :: geometry ) :: json ) FROM geo_sungai a, geo_prov_kab b")
prov_res = sungai.fetchall()
data = {'gen':prov_res}
return Response(data)
@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def editpoly(request):
if request.method == 'GET':
id_poly = request.GET.get("id_poly")
with conn.cursor() as buldings:
buldings.execute("SELECT json_build_object('type', 'Feature', 'properties', (id, name, information, 'osm'), 'administrasi',(address_1, address_2, address_3, provinsi, 'no'), 'geometry', ST_AsGeoJSON(geom :: geometry) :: json) FROM geo_bangunan WHERE id = %s"% int(id_poly))
build = buldings.fetchall()
return Response(build[0][0])
import json
@api_view(('POST',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def validatedit(request):
if request.method == 'POST':
name_b = request.POST.get("name_b")
info_b = request.POST.get("info_b")
desa_b = request.POST.get("desa_b")
kec_b = request.POST.get("kec_b")
kab_b = request.POST.get("kab_b")
pro_b = request.POST.get("pro_b")
id_poly = request.POST.get("id_poly")
polygon = request.POST.get("polygon")
cood_edit = json.loads(polygon)
co_edit = cood_edit['geometry']['coordinates']
print(id_poly, name_b, info_b, polygon)
with conn.cursor() as buldings:
buldings.execute("""UPDATE geo_bangunan set geom = st_geomfromgeojson('{"type":"MultiPolygon", "coordinates":[%s]}'),name='%s',information='%s',address_1='%s', address_2 = '%s', address_3 = '%s', provinsi='%s' WHERE id = %s"""% (co_edit,name_b, info_b, desa_b, kec_b, kab_b, pro_b, int(id_poly)))
conn.commit()
data = {'status':'Success'}
return Response(data)
@api_view(('POST',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def hapus(request):
if request.method == 'POST':
id_poly = request.POST.get("id_poly")
with conn.cursor() as buldings:
buldings.execute("""DELETE from geo_bangunan where id = %s"""% int(id_poly))
conn.commit()
data = {'status':'Success'}
return Response(data)
@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def hasilsearch(request):
if request.method == 'GET':
id_desa = request.GET.get("id_desa_search")
with conn.cursor() as kel:
kel.execute("SELECT json_build_object('type', 'Feature', 'administrasi', (kode_desa, desa, kecamatan, kab_kota, provinsi, jumlah_pen, jumlah_kk, luas_desa),'penduduk', (pria, wanita, belum_kawin, kawin, cerai_hidup, cerai_mati, wajib_ktp, islam, kristen, khatolik, hindu, budha, konghucu, kepercayaan_lain, u0, u5, u10, u15, u20, u25, u30, u35, u40, u45, u50, u55, u60, u65, u70, u75),'pekerjaan_pendidikan', (tidak_sekolah, belum_tamat, tamat_sd, sltp, slta, diploma_i, diploma_ii, diploma_iv, strata_ii, strata_iii, tidak_bekerja, aparatur_pemerintah, tenaga_pendidik, wiraswasta, pertanian, tenaga_kesehatan, pensiunan, pegawai, tentara, kepolisian, pedagang, petani, peternak, nelayan, karyawan, buruh, pembantu, tukang, pendeta, pastor, ustadz, dosen, guru, pilot, pengacara, notaris, arsitek, akuntan, konsultan, dokter, bidan, perawat, psikiater, sopir, lainnya),'geometry', ST_AsGeoJSON(geom :: geometry) :: json) from geo_data_kelurahan where id = %s"% int(id_desa))
kel_res_ = kel.fetchall()
kel_res = []
for i in kel_res_:
kel_res.append(i[0])
data = {'result':kel_res}
return Response(data)
\ No newline at end of file
...@@ -19,9 +19,13 @@ class Dashboard(generic.TemplateView): ...@@ -19,9 +19,13 @@ class Dashboard(generic.TemplateView):
kel_res_ = kel.fetchall() kel_res_ = kel.fetchall()
with conn.cursor() as kec: with conn.cursor() as kec:
kec.execute("SELECT kecamatan, json_build_object('type', 'Feature','geometry', ST_AsGeoJSON(geom :: geometry) :: json) from geo_data_kecamatan") kec.execute("SELECT kecamatan, json_build_object('type', 'Feature', 'administrasi', (id, kecamatan),'geometry', ST_AsGeoJSON(geom :: geometry) :: json) from geo_data_kecamatan")
kec_res_ = kec.fetchall() kec_res_ = kec.fetchall()
with conn.cursor() as knt:
knt.execute("SELECT json_build_object('type', 'Feature', 'administrasi', (a.namobj, a.remark),'geometry', ST_AsGeoJSON(a.geom :: geometry) :: json) from geo_kantor_administrasi a join geo_prov_kab b on st_intersects(a.geom,b.geom)")
knt_res = knt.fetchall()
kec_res = [] kec_res = []
for i in kec_res_: for i in kec_res_:
kec_res.append(i[1]) kec_res.append(i[1])
...@@ -30,12 +34,120 @@ class Dashboard(generic.TemplateView): ...@@ -30,12 +34,120 @@ class Dashboard(generic.TemplateView):
for i in kel_res_: for i in kel_res_:
kel_res.append(i[0]) kel_res.append(i[0])
kntl = []
for i in knt_res:
kntl.append(i[0])
with conn.cursor() as kantor_administrasi:
kantor_administrasi.execute("SELECT json_build_object('type', 'Feature', 'administrasi', (a.namobj, a.remark),'geometry', ST_AsGeoJSON(a.geom :: geometry) :: json) from geo_kantor_administrasi a join geo_prov_kab b on st_intersects(a.geom,b.geom)")
kantor_administrasi_res = kantor_administrasi.fetchall()
kantor_administrasi_result = []
for i in kantor_administrasi_res:
kantor_administrasi_result.append(i[0])
with conn.cursor() as layanan_kesehatan:
layanan_kesehatan.execute("SELECT json_build_object('type', 'Feature', 'administrasi', (a.namobj, a.remark), 'geometry', ST_AsGeoJSON(a.geom :: geometry) :: json) from geo_layanan_kesehatan a join geo_prov_kab b on st_intersects(a.geom,b.geom)")
layanan_kesehatan_res = layanan_kesehatan.fetchall()
layanan_kesehatan_result = []
for i in layanan_kesehatan_res:
layanan_kesehatan_result.append(i[0])
with conn.cursor() as puskesmas:
puskesmas.execute("SELECT json_build_object('type', 'Feature', 'administrasi', (a.namobj, a.remark), 'geometry', ST_AsGeoJSON(a.geom :: geometry) :: json) from geo_puskesmas a join geo_prov_kab b on st_intersects(a.geom,b.geom)")
puskesmas_res = puskesmas.fetchall()
puskesmas_result = []
for i in puskesmas_res:
puskesmas_result.append(i[0])
with conn.cursor() as rumah_sakit:
rumah_sakit.execute("SELECT json_build_object('type', 'Feature', 'administrasi', (a.namobj, a.remark), 'geometry', ST_AsGeoJSON(a.geom :: geometry) :: json) from geo_rumah_sakit a join geo_prov_kab b on st_intersects(a.geom,b.geom)")
rumah_sakit_res = rumah_sakit.fetchall()
rumah_sakit_result = []
for i in rumah_sakit_res:
rumah_sakit_result.append(i[0])
with conn.cursor() as sarana_ibadah:
sarana_ibadah.execute("SELECT json_build_object('type', 'Feature', 'administrasi', (a.namobj, a.remark), 'geometry', ST_AsGeoJSON(a.geom :: geometry) :: json) from geo_sarana_ibadah a join geo_prov_kab b on st_intersects(a.geom,b.geom)")
sarana_ibadah_res = sarana_ibadah.fetchall()
sarana_ibadah_result = []
for i in sarana_ibadah_res:
if i[0]["administrasi"]['f1'] == None:
i[0]["administrasi"]['f1'] = "None"
sarana_ibadah_result.append(i[0])
with conn.cursor() as sarana_pendidikan:
sarana_pendidikan.execute("SELECT json_build_object('type', 'Feature', 'administrasi', (a.namobj, a.remark), 'geometry', ST_AsGeoJSON(a.geom :: geometry) :: json) from geo_sarana_pendidikan a join geo_prov_kab b on st_intersects(a.geom,b.geom)")
sarana_pendidikan_res = sarana_pendidikan.fetchall()
sarana_pendidikan_result = []
for i in sarana_pendidikan_res:
if i[0]["administrasi"]['f1'] == None:
i[0]["administrasi"]['f1'] = "None"
sarana_pendidikan_result.append(i[0])
with conn.cursor() as spbu:
spbu.execute("SELECT json_build_object('type', 'Feature', 'administrasi', (a.namobj, a.remark), 'geometry', ST_AsGeoJSON(a.geom :: geometry) :: json) from geo_spbu a join geo_prov_kab b on st_intersects(a.geom,b.geom)")
spbu_res = spbu.fetchall()
spbu_result = []
for i in spbu_res:
spbu_result.append(i[0])
with conn.cursor() as stasiun:
stasiun.execute("SELECT json_build_object('type', 'Feature', 'administrasi', (a.namobj, a.remark), 'geometry', ST_AsGeoJSON(a.geom :: geometry) :: json) from geo_stasiun a join geo_prov_kab b on st_intersects(a.geom,b.geom)")
stasiun_res = stasiun.fetchall()
stasiun_result = []
for i in stasiun_res:
stasiun_result.append(i[0])
with conn.cursor() as terminal:
terminal.execute("SELECT json_build_object('type', 'Feature', 'administrasi', (a.namobj, a.remark), 'geometry', ST_AsGeoJSON(a.geom :: geometry) :: json) from geo_terminal_bus a join geo_prov_kab b on st_intersects(a.geom,b.geom)")
terminal_res = terminal.fetchall()
terminal_result = []
for i in terminal_res:
terminal_result.append(i[0])
with conn.cursor() as cagar_budaya:
cagar_budaya.execute("SELECT json_build_object('type', 'Feature', 'administrasi', (a.namobj, a.remark), 'geometry', ST_AsGeoJSON(a.geom :: geometry) :: json) from geo_cagar_budaya a join geo_prov_kab b on st_intersects(a.geom,b.geom)")
cagar_budaya_res = cagar_budaya.fetchall()
cagar_budaya_result = []
for i in cagar_budaya_res:
cagar_budaya_result.append(i[0])
with conn.cursor() as gardu_listrik:
gardu_listrik.execute("SELECT json_build_object('type', 'Feature', 'administrasi', (a.namobj, a.remark), 'geometry', ST_AsGeoJSON(a.geom :: geometry) :: json) from geo_gardu_listrik a join geo_prov_kab b on st_intersects(a.geom,b.geom)")
gardu_listrik_res = gardu_listrik.fetchall()
gardu_listrik_result = []
for i in gardu_listrik_res:
gardu_listrik_result.append(i[0])
print(all) print(all)
context = { context = {
'title':'NA - Dashboard', 'title':'NA - Dashboard',
'kelurahan':kel_res, 'kelurahan':kel_res,
'kecamatan':kec_res, 'kecamatan':kec_res,
'global':all[0] 'kantor_administrasi':kantor_administrasi_result,
'layanan_kesehatan':layanan_kesehatan_result,
'puskesmas':puskesmas_result,
'rumah_sakit':rumah_sakit_result,
'sarana_ibadah':sarana_ibadah_result,
'sarana_pendidikan':sarana_pendidikan_result,
'spbu':spbu_result,
'stasiun':stasiun_result,
'terminal':terminal_result,
'cagar_budaya':cagar_budaya_result,
'gardu_listrik':gardu_listrik_result,
'global':all[0],
'kntl':kntl
} }
return render (request, self.template_name, context) return render (request, self.template_name, context)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment