views.py 86.6 KB
Newer Older
Muhamad's avatar
Muhamad committed
1 2
from django.http.response import Http404
from django.shortcuts import redirect, render
Manggar Mahardhika's avatar
Manggar Mahardhika committed
3 4 5
from rest_framework import status
from rest_framework.decorators import api_view, renderer_classes
from rest_framework.response import Response
Muhamad's avatar
Muhamad committed
6 7 8 9 10 11 12 13
from django.core.files.storage import FileSystemStorage
from django.core.files.base import ContentFile, File
import base64
import json
from PIL import Image
from django.contrib.auth.decorators import login_required, user_passes_test
from django.utils.decorators import method_decorator

Manggar Mahardhika's avatar
Manggar Mahardhika committed
14
from django.db import connection as conn
Manggar Mahardhika's avatar
Manggar Mahardhika committed
15 16

# Create your views here.
Manggar Mahardhika's avatar
Manggar Mahardhika committed
17 18
from rest_framework.renderers import JSONRenderer, TemplateHTMLRenderer

Muhamad's avatar
Muhamad committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
# from django.utils import six
import six
from django.core.exceptions import PermissionDenied
from django.contrib.auth.decorators import user_passes_test
from django.http import HttpResponse, HttpResponseNotFound


def group_required(group, login_url=None, raise_exception=False):
    def check_perms(user):

        if isinstance(group, six.string_types):
            groups = (group, )
        else:
            groups = group

34
        if user.groups.filter(name__in=groups).exists() or user.is_superuser:
Muhamad's avatar
Muhamad committed
35 36 37 38 39 40 41 42 43 44 45
            return True

        if raise_exception:
            print('raise')
            raise PermissionDenied("dilarang")

        return False

    return user_passes_test(check_perms, login_url=login_url)


Manggar Mahardhika's avatar
Manggar Mahardhika committed
46 47
import random

Manggar Mahardhika's avatar
Manggar Mahardhika committed
48 49 50
@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def search_auto(request):
Muhamad's avatar
Muhamad committed
51

Manggar Mahardhika's avatar
Manggar Mahardhika committed
52
    with conn.cursor() as desa:
Muhamad's avatar
Muhamad committed
53
        desa.execute(f"SELECT id, desa, kecamatan FROM geo_data_kelurahan order by desa ASC")
Manggar Mahardhika's avatar
Manggar Mahardhika committed
54 55 56
        all = desa.fetchall()    
        
    data = {'nama_des':all}
Manggar Mahardhika's avatar
Manggar Mahardhika committed
57 58 59 60
    return Response(data)

@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
Muhamad's avatar
Muhamad committed
61

Manggar Mahardhika's avatar
Manggar Mahardhika committed
62 63
def tuplah(request):
    with conn.cursor() as desa:
Muhamad's avatar
Muhamad committed
64
        desa.execute(f"SELECT json_build_object('type', 'Feature', 'legend', (a.id, a.legenda, st_area(a.geom::geography), a.gambar) ,'geometry', ST_AsGeoJSON( st_intersection(a.geom, b.geom):: geometry) :: json) from geo_tuplah a, geo_prov_kab b")
Manggar Mahardhika's avatar
Manggar Mahardhika committed
65 66 67 68 69
        all = desa.fetchall()    
        
    data = {'tuplah':all}
    return Response(data)

Muhamad's avatar
Muhamad committed
70 71


Manggar Mahardhika's avatar
Manggar Mahardhika committed
72 73 74 75 76 77 78 79 80 81 82 83 84
@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:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
85
            buldings.execute("SELECT json_build_object('type', 'Feature', 'properties', (id, name, information), 'administrasi',(address_1, address_2, address_3, provinsi, alamat, luas_bangunan, luas_tanah, tinggi_bangunan, gambar, pemilik, db_tipe, remark, point_id, point_name), '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))
Manggar Mahardhika's avatar
Manggar Mahardhika committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
            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")
Muhamad's avatar
Muhamad committed
104
        print(kulon, lor, wetan, lor, wetan, kidul, kulon, kidul, kulon, lor, kulon, lor, wetan, lor, wetan, kidul, kulon, kidul, kulon, lor)
Muhamad's avatar
Muhamad committed
105

Manggar Mahardhika's avatar
Manggar Mahardhika committed
106
        with conn.cursor() as jalan:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
107
            jalan.execute("SELECT json_build_object ('type', 'Feature', 'properties', ( gj.ID, namrjl, st_length ( gj.geom :: geography ), gj.lebar_jalan, gj.remark, gj.gambar,(SELECT ARRAY_AGG ( '' || id || ',' || tgl_perbaikan || '' order by tgl_perbaikan DESC ) FROM tbl_perbaikan WHERE id_object = gj.ID and type_id = 2) ), 'geometry', ST_AsGeoJSON ( st_intersection(gj.geom, 'SRID=4326;POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))') :: geometry ) :: json ) FROM geo_jalan gj WHERE st_intersects(gj.geom,'SRID=4326;POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))') GROUP BY gj.id"% (kulon, lor, wetan, lor, wetan, kidul, kulon, kidul, kulon, lor, kulon, lor, wetan, lor, wetan, kidul, kulon, kidul, kulon, lor))
Manggar Mahardhika's avatar
Manggar Mahardhika committed
108 109 110 111 112
            prov_res = jalan.fetchall()
                                
        data = {'gen':prov_res}
        return Response(data)
    
Muhamad's avatar
Muhamad committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    
@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))

def editjalan(request):
    if request.method == 'GET':
        idjalan = request.GET.get("idjalan")

        with conn.cursor() as jalan:
            jalan.execute("SELECT json_build_object ('geometry', ST_AsGeoJSON (geom :: geometry ) :: json ) FROM geo_jalan WHERE id = %s"% idjalan)
            prov_res = jalan.fetchall()
                                
        data = {'jalan':prov_res[0][0]}
        return Response(data)

@api_view(('POST',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))

def editjalanvalid(request):
    file = request.FILES.get('file')
    idjalan = request.POST.get('idjalan')
    namajalan = request.POST.get('namajalan')
    panjangjalan = request.POST.get('panjangjalan')
    tipejalan = request.POST.get('tipejalan')
    lebarjalan = request.POST.get('lebarjalan')
    cordi = request.POST.get('cord')
    cord = json.loads(cordi)
    
    # fss = FileSystemStorage(location='static/image/jalan/')
    # try:
    #     format = (file.name).split(".")
    #     num = random.randrange(1, 10000000000000)
    #     namafile = f"{idjalan}_{num}.{format[-1:][0]}"
    #     filename = fss.save(namafile, file)
    #     url = fss.url(filename)
    # except:
    #     num = random.randrange(1, 10000000000000)
    #     namafile = file.name
    #     filename = fss.save(namafile, file)
    #     url = fss.url(filename)
    
    # try:
    with conn.cursor() as desa:
        desa.execute("""UPDATE geo_jalan set geom = st_setsrid(st_geomfromgeojson('{"type":"MultiLineString", "coordinates":[%s]}'),4326), namrjl = '%s', panjang_jalan = %s, lebar_jalan = %s, remark = '%s' where id=%s"""%(cord['geometry']['coordinates'], namajalan, panjangjalan, lebarjalan, tipejalan, int(idjalan)))
    conn.commit()
        
    data = 'SUCCESS'
    info = 'data telah diperbaharui'
    status = 0
    # except:
    #     data = 'NOT SUCCESS'
    #     info = 'Hubungi Orang Server'
    #     status = 1
    
    respon={'data':data, 'info':info, 'code':status}
    return Response(respon)


Manggar Mahardhika's avatar
Manggar Mahardhika committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
@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:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
196
            buldings.execute("SELECT json_build_object('type', 'Feature', 'properties', (id, name, information, 'osm'), 'administrasi',(address_1, address_2, address_3, provinsi, alamat, luas_bangunan, luas_tanah, tinggi_bangunan, gambar, pemilik, db_tipe, remark, point_id), 'geometry', ST_AsGeoJSON(geom :: geometry) :: json) FROM geo_bangunan WHERE id = %s"% int(id_poly))
Manggar Mahardhika's avatar
Manggar Mahardhika committed
197 198 199 200
            build = buldings.fetchall()
        
        return Response(build[0][0])

Manggar Mahardhika's avatar
Manggar Mahardhika committed
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def editpointka(request):
    if request.method == 'GET':
        id_point = request.GET.get("id_point")                   
        with conn.cursor() as buldings:
            buldings.execute("""SELECT
                                    json_build_object (
                                        'type',
                                        'Feature',
                                        'administrasi',
                                        (
                                            A.namobj,
                                            A.remark,
                                            A.alamat,
                                            A.luas_bangunan,
                                            A.luas_tanah,
                                            A.satuan_luas_bangunan,
                                            A.satuan_luas_tanah,
                                            A.gambar,
                                            A.tinggi_bangunan,
                                            A.perangkat,
                                            A.tipe_gambar,
                                            b.kabupaten,
                                            c.kecamatan,
                                            d.desa,
                                            a.id
                                        ),
                                        'geometry',
                                        ST_AsGeoJSON ( A.geom :: geometry ) :: json 
                                    ) 
                                FROM
                                    geo_kantor_administrasi A 
                                    JOIN geo_prov_kab b ON st_intersects ( A.geom, b.geom )
                                    JOIN geo_data_kecamatan c ON st_intersects(A.geom, c.geom)
                                    join geo_data_kelurahan d on st_intersects(A.geom, d.geom) 
237
                                WHERE a.is_deleted = 0 and a.id = %s"""% int(id_point))
Manggar Mahardhika's avatar
Manggar Mahardhika committed
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
            build = buldings.fetchall()
        
        return Response(build[0][0])

@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def editpointlk(request):
    if request.method == 'GET':
        id_point = request.GET.get("id_point")                   
        with conn.cursor() as buldings:
            buldings.execute("""SELECT
                                    json_build_object (
                                        'type',
                                        'Feature',
                                        'administrasi',
                                        (
                                            A.namobj,
                                            A.remark,
                                            A.alamat,
                                            A.luas_bangunan,
                                            A.luas_tanah,
                                            A.satuan_luas_bangunan,
                                            A.satuan_luas_tanah,
                                            A.gambar,
                                            A.tinggi_bangunan,
                                            A.perangkat,
                                            A.tipe_gambar,
                                            b.kabupaten,
                                            c.kecamatan,
                                            d.desa,
                                            a.id
                                        ),
                                        'geometry',
                                        ST_AsGeoJSON ( A.geom :: geometry ) :: json 
                                    ) 
                                FROM
                                    geo_layanan_kesehatan A 
                                    JOIN geo_prov_kab b ON st_intersects ( A.geom, b.geom )
                                    JOIN geo_data_kecamatan c ON st_intersects(A.geom, c.geom)
                                    join geo_data_kelurahan d on st_intersects(A.geom, d.geom)
                                WHERE a.id = %s"""% int(id_point))
            build = buldings.fetchall()
        
        return Response(build[0][0])

@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def editpointpks(request):
    if request.method == 'GET':
        id_point = request.GET.get("id_point")                   
        with conn.cursor() as buldings:
            buldings.execute("""SELECT
                                    json_build_object (
                                        'type',
                                        'Feature',
                                        'administrasi',
                                        (
                                            A.namobj,
                                            A.remark,
                                            A.alamat,
                                            A.luas_bangunan,
                                            A.luas_tanah,
                                            A.satuan_luas_bangunan,
                                            A.satuan_luas_tanah,
                                            A.gambar,
                                            A.tinggi_bangunan,
                                            A.perangkat,
                                            A.tipe_gambar,
                                            b.kabupaten,
                                            c.kecamatan,
                                            d.desa,
                                            a.id
                                        ),
                                        'geometry',
                                        ST_AsGeoJSON ( A.geom :: geometry ) :: json 
                                    ) 
                                FROM
                                    geo_puskesmas A 
                                    JOIN geo_prov_kab b ON st_intersects ( A.geom, b.geom )
                                    JOIN geo_data_kecamatan c ON st_intersects(A.geom, c.geom)
                                    join geo_data_kelurahan d on st_intersects(A.geom, d.geom)
                                WHERE a.id = %s"""% int(id_point))
            build = buldings.fetchall()
        
        return Response(build[0][0])

@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def editpointrs(request):
    if request.method == 'GET':
        id_point = request.GET.get("id_point")                   
        with conn.cursor() as buldings:
            buldings.execute("""SELECT
                                    json_build_object (
                                        'type',
                                        'Feature',
                                        'administrasi',
                                        (
                                            A.namobj,
                                            A.remark,
                                            A.alamat,
                                            A.luas_bangunan,
                                            A.luas_tanah,
                                            A.satuan_luas_bangunan,
                                            A.satuan_luas_tanah,
                                            A.gambar,
                                            A.tinggi_bangunan,
                                            A.perangkat,
                                            A.tipe_gambar,
                                            b.kabupaten,
                                            c.kecamatan,
                                            d.desa,
                                            a.id
                                        ),
                                        'geometry',
                                        ST_AsGeoJSON ( A.geom :: geometry ) :: json 
                                    ) 
                                FROM
                                    geo_rumah_sakit A 
                                    JOIN geo_prov_kab b ON st_intersects ( A.geom, b.geom )
                                    JOIN geo_data_kecamatan c ON st_intersects(A.geom, c.geom)
                                    join geo_data_kelurahan d on st_intersects(A.geom, d.geom)
                                WHERE a.id = %s"""% int(id_point))
            build = buldings.fetchall()
        
        return Response(build[0][0])

@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def editpointsi(request):
    if request.method == 'GET':
        id_point = request.GET.get("id_point")                   
        with conn.cursor() as buldings:
            buldings.execute("""SELECT
                                    json_build_object (
                                        'type',
                                        'Feature',
                                        'administrasi',
                                        (
                                            A.namobj,
                                            A.remark,
                                            A.alamat,
                                            A.luas_bangunan,
                                            A.luas_tanah,
                                            A.satuan_luas_bangunan,
                                            A.satuan_luas_tanah,
                                            A.gambar,
                                            A.tinggi_bangunan,
                                            A.perangkat,
                                            A.tipe_gambar,
                                            b.kabupaten,
                                            c.kecamatan,
                                            d.desa,
                                            a.id
                                        ),
                                        'geometry',
                                        ST_AsGeoJSON ( A.geom :: geometry ) :: json 
                                    ) 
                                FROM
                                    geo_sarana_ibadah A 
                                    JOIN geo_prov_kab b ON st_intersects ( A.geom, b.geom )
                                    JOIN geo_data_kecamatan c ON st_intersects(A.geom, c.geom)
                                    join geo_data_kelurahan d on st_intersects(A.geom, d.geom)
                                WHERE a.id = %s"""% int(id_point))
            build = buldings.fetchall()
        
        return Response(build[0][0])

@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def editpointsp(request):
    if request.method == 'GET':
        id_point = request.GET.get("id_point")                   
        with conn.cursor() as buldings:
            buldings.execute("""SELECT
                                    json_build_object (
                                        'type',
                                        'Feature',
                                        'administrasi',
                                        (
                                            A.namobj,
                                            A.remark,
                                            A.alamat,
                                            A.luas_bangunan,
                                            A.luas_tanah,
                                            A.satuan_luas_bangunan,
                                            A.satuan_luas_tanah,
                                            A.gambar,
                                            A.tinggi_bangunan,
                                            A.perangkat,
                                            A.tipe_gambar,
                                            b.kabupaten,
                                            c.kecamatan,
                                            d.desa,
                                            a.id
                                        ),
                                        'geometry',
                                        ST_AsGeoJSON ( A.geom :: geometry ) :: json 
                                    ) 
                                FROM
                                    geo_sarana_pendidikan A 
                                    JOIN geo_prov_kab b ON st_intersects ( A.geom, b.geom )
                                    JOIN geo_data_kecamatan c ON st_intersects(A.geom, c.geom)
                                    join geo_data_kelurahan d on st_intersects(A.geom, d.geom)
                                WHERE a.id = %s"""% int(id_point))
            build = buldings.fetchall()
        
        return Response(build[0][0])

@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def editpointspbu(request):
    if request.method == 'GET':
        id_point = request.GET.get("id_point")                   
        with conn.cursor() as buldings:
            buldings.execute("""SELECT
                                    json_build_object (
                                        'type',
                                        'Feature',
                                        'administrasi',
                                        (
                                            A.namobj,
                                            A.remark,
                                            A.alamat,
                                            A.luas_bangunan,
                                            A.luas_tanah,
                                            A.satuan_luas_bangunan,
                                            A.satuan_luas_tanah,
                                            A.gambar,
                                            A.tinggi_bangunan,
                                            A.perangkat,
                                            A.tipe_gambar,
                                            b.kabupaten,
                                            c.kecamatan,
                                            d.desa,
                                            a.id
                                        ),
                                        'geometry',
                                        ST_AsGeoJSON ( A.geom :: geometry ) :: json 
                                    ) 
                                FROM
                                    geo_spbu A 
                                    JOIN geo_prov_kab b ON st_intersects ( A.geom, b.geom )
                                    JOIN geo_data_kecamatan c ON st_intersects(A.geom, c.geom)
                                    join geo_data_kelurahan d on st_intersects(A.geom, d.geom)
                                WHERE a.id = %s"""% int(id_point))
            build = buldings.fetchall()
        
        return Response(build[0][0])

@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def editpointst(request):
    if request.method == 'GET':
        id_point = request.GET.get("id_point")                   
        with conn.cursor() as buldings:
            buldings.execute("""SELECT
                                    json_build_object (
                                        'type',
                                        'Feature',
                                        'administrasi',
                                        (
                                            A.namobj,
                                            A.remark,
                                            A.alamat,
                                            A.luas_bangunan,
                                            A.luas_tanah,
                                            A.satuan_luas_bangunan,
                                            A.satuan_luas_tanah,
                                            A.gambar,
                                            A.tinggi_bangunan,
                                            A.perangkat,
                                            A.tipe_gambar,
                                            b.kabupaten,
                                            c.kecamatan,
                                            d.desa,
                                            a.id
                                        ),
                                        'geometry',
                                        ST_AsGeoJSON ( A.geom :: geometry ) :: json 
                                    ) 
                                FROM
                                    geo_stasiun A 
                                    JOIN geo_prov_kab b ON st_intersects ( A.geom, b.geom )
                                    JOIN geo_data_kecamatan c ON st_intersects(A.geom, c.geom)
                                    join geo_data_kelurahan d on st_intersects(A.geom, d.geom)
                                WHERE a.id = %s"""% int(id_point))
            build = buldings.fetchall()
        
        return Response(build[0][0])

@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def editpointgl(request):
    if request.method == 'GET':
        id_point = request.GET.get("id_point")                   
        with conn.cursor() as buldings:
            buldings.execute("""SELECT
                                    json_build_object (
                                        'type',
                                        'Feature',
                                        'administrasi',
                                        (
                                            A.namobj,
                                            A.remark,
                                            A.alamat,
                                            A.luas_bangunan,
                                            A.luas_tanah,
                                            A.satuan_luas_bangunan,
                                            A.satuan_luas_tanah,
                                            A.gambar,
                                            A.tinggi_bangunan,
                                            A.perangkat,
                                            A.tipe_gambar,
                                            b.kabupaten,
                                            c.kecamatan,
                                            d.desa,
                                            a.id
                                        ),
                                        'geometry',
                                        ST_AsGeoJSON ( A.geom :: geometry ) :: json 
                                    ) 
                                FROM
                                    geo_gardu_listrik A 
                                    JOIN geo_prov_kab b ON st_intersects ( A.geom, b.geom )
                                    JOIN geo_data_kecamatan c ON st_intersects(A.geom, c.geom)
                                    join geo_data_kelurahan d on st_intersects(A.geom, d.geom)
                                WHERE a.id = %s"""% int(id_point))
            build = buldings.fetchall()
        
        return Response(build[0][0])

@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def editpointtr(request):
    if request.method == 'GET':
        id_point = request.GET.get("id_point")                   
        with conn.cursor() as buldings:
            buldings.execute("""SELECT
                                    json_build_object (
                                        'type',
                                        'Feature',
                                        'administrasi',
                                        (
                                            A.namobj,
                                            A.remark,
                                            A.alamat,
                                            A.luas_bangunan,
                                            A.luas_tanah,
                                            A.satuan_luas_bangunan,
                                            A.satuan_luas_tanah,
                                            A.gambar,
                                            A.tinggi_bangunan,
                                            A.perangkat,
                                            A.tipe_gambar,
                                            b.kabupaten,
                                            c.kecamatan,
                                            d.desa,
                                            a.luas,
                                            a.id
                                        ),
                                        'geometry',
                                        ST_AsGeoJSON ( A.geom :: geometry ) :: json 
                                    ) 
                                FROM
                                    geo_terminal_bus A 
                                    JOIN geo_prov_kab b ON st_intersects ( A.geom, b.geom )
                                    JOIN geo_data_kecamatan c ON st_intersects(A.geom, c.geom)
                                    join geo_data_kelurahan d on st_intersects(A.geom, d.geom)
                                WHERE a.id = %s"""% int(id_point))
            build = buldings.fetchall()
        
        return Response(build[0][0])

@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def editpointcb(request):
    if request.method == 'GET':
        id_point = request.GET.get("id_point")                   
        with conn.cursor() as buldings:
            buldings.execute("""SELECT
                                        json_build_object (
                                            'type',
                                            'Feature',
                                            'administrasi',
                                            (
                                                A.namobj,
                                                A.remark,
                                                A.alamat,
                                                A.gambar,
                                                A.perangkat,
                                                A.tipe_gambar,
                                                b.kabupaten,
                                                c.kecamatan,
                                                d.desa,
                                                a.luas,
                                                a.id
                                            ),
                                            'geometry',
                                            ST_AsGeoJSON ( A.geom :: geometry ) :: json 
                                        ) 
                                    FROM
                                        geo_cagar_budaya A  
                                    JOIN geo_prov_kab b ON st_intersects ( A.geom, b.geom )
                                    JOIN geo_data_kecamatan c ON st_intersects(A.geom, c.geom)
                                    join geo_data_kelurahan d on st_intersects(A.geom, d.geom)
                                WHERE a.id = %s"""% int(id_point))
            build = buldings.fetchall()
        
        return Response(build[0][0])

649 650
import json

Manggar Mahardhika's avatar
Manggar Mahardhika committed
651 652 653 654 655 656 657 658 659 660
@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")
661
        gmb_b = request.POST.get("gambar")
Manggar Mahardhika's avatar
Manggar Mahardhika committed
662
        
Manggar Mahardhika's avatar
Manggar Mahardhika committed
663 664 665 666 667
        luast_b = request.POST.get("luastanah_b")
        luasb_b = request.POST.get("luasbangunan_b")
        tinggi_b = request.POST.get("tinggibangunan_b")
        pemilik_b = request.POST.get("pemilik_b")
        
Manggar Mahardhika's avatar
Manggar Mahardhika committed
668 669
        id_poly = request.POST.get("id_poly")
        polygon = request.POST.get("polygon")
Muhamad's avatar
Muhamad committed
670
        print(polygon)
Manggar Mahardhika's avatar
Manggar Mahardhika committed
671 672 673
        cood_edit = json.loads(polygon)
            
        co_edit = cood_edit['geometry']['coordinates']
Muhamad's avatar
Muhamad committed
674 675 676 677 678 679 680 681 682 683 684 685 686
        print(co_edit,name_b, info_b, desa_b, kec_b, kab_b, pro_b, id_poly)

        file = request.FILES.get('file')
        fss = FileSystemStorage(location='static/image/bangunan/')

        try:
            try:
                format = (file.name).split(".")
                num = random.randrange(1, 10000000000000)
                namafile = f"{name_b}_{num}.{format[-1:][0]}"
                filename = fss.save(namafile, file)
                url = fss.url(filename)
            except:
687
                namafile = gmb_b
Muhamad's avatar
Muhamad committed
688
            print(co_edit,name_b, info_b, desa_b, kec_b, kab_b, pro_b, namafile, int(id_poly))
Manggar Mahardhika's avatar
Manggar Mahardhika committed
689
            
Muhamad's avatar
Muhamad committed
690
            with conn.cursor() as buldings:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
691
                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', gambar = '%s', is_deleted = 0, luas_bangunan=%s, luas_tanah=%s, tinggi_bangunan=%s, pemilik='%s' WHERE id = %s"""% (co_edit,name_b, info_b, desa_b, kec_b, kab_b, pro_b, namafile, luasb_b, luast_b, tinggi_b, pemilik_b, int(id_poly)))
Muhamad's avatar
Muhamad committed
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
            conn.commit()
            
            data = 'SUCCESS'
            info = 'data telah diperbaharui'
            status = 0
            
        except:
            data = 'SORRY'
            info = 'hubungi orang terdekat'
            status = 1
            
        respon = {
            'data':data, 
            'info':info, 
            'code':status,
        }
        print(respon)
            
        return Response(respon)
Manggar Mahardhika's avatar
Manggar Mahardhika committed
711 712 713 714 715
    
@api_view(('POST',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def hapus(request):
    if request.method == 'POST':
716 717
        try:
            id_poly = request.POST.get("id_poly")
Manggar Mahardhika's avatar
Manggar Mahardhika committed
718

719 720 721
            with conn.cursor() as buldings:
                buldings.execute("""DELETE from geo_bangunan where id = %s"""% int(id_poly))
            conn.commit()
Manggar Mahardhika's avatar
Manggar Mahardhika committed
722
            
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
            data = 'SUCCESS'
            info = 'data telah diperbaharui'
            status = 0
            
        except:
            data = 'SORRY'
            info = 'hubungi orang terdekat'
            status = 1
            
        respon = {
            'data':data, 
            'info':info, 
            'code':status,
        }
        print(respon)
            
        return Response(respon)
Muhamad's avatar
Muhamad committed
740

Manggar Mahardhika's avatar
Manggar Mahardhika committed
741 742 743 744
@api_view(('GET',))
@renderer_classes((TemplateHTMLRenderer, JSONRenderer))
def hasilsearch(request):
    if request.method == 'GET':
Muhamad's avatar
Muhamad committed
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
        nama_desa = request.GET.get("id_desa_search")
        
        nama_desa = nama_desa.split(",")[0]
        with conn.cursor() as bts:
            bts.execute("""
                        SELECT
                            st_asgeojson ( ST_ExteriorRing ( the_geom ) ) AS erings 
                        FROM
                            ( SELECT ( ST_Dump ( geom ) ).geom AS the_geom FROM geo_data_kelurahan WHERE desa = '%s' ) as foo
                        """% nama_desa)
            batas = bts.fetchall()
            # batas_desa = json.loads(batas)
            line_o = []
            for i in batas:
                o_pol1 = ''
                o_poly = []
                
                for x in json.loads(i[0])['coordinates']:
                    o_pol1 += (f'{x[0]},{x[1]}""')
                
                o_pol2 = o_pol1.replace('""1',',1')

                o_poly.append(o_pol2.replace('""',''))
                
                line_o.append(o_poly)
        
        with conn.cursor() as desa:
            desa.execute("""
                        SELECT
                            ST_AsGeoJson ( ST_centroid ( geom ) ) 
                        FROM
                            geo_data_kelurahan 
                        WHERE
                            desa = '%s'"""% nama_desa)
            lat_lng = desa.fetchall()
        
        with conn.cursor() as bang:
            bang.execute("""SELECT
                                json_build_object (
                                    'type',
                                    'Feature',
                                    'properties',
                                    ( buildings.ID, buildings.NAME, buildings.information ),
                                    'administrasi',
                                    (
                                        buildings.address_1,
                                        buildings.address_2,
                                        buildings.address_3,
                                        buildings.provinsi,
                                        buildings.alamat,
                                        buildings.luas_bangunan,
                                        buildings.luas_tanah,
                                        buildings.tinggi_bangunan,
                                        buildings.gambar,
                                        buildings.pemilik 
                                    ),
                                    'geometry',
                                    ST_AsGeoJSON ( buildings.geom :: geometry ) :: json 
                                ) 
                            FROM
                                geo_bangunan buildings
                                JOIN geo_data_kelurahan desa ON st_intersects (  ST_SetSRID(desa.geom, 0), buildings.geom ) 
                            WHERE
                                desa.desa = '%s'"""% nama_desa)
Manggar Mahardhika's avatar
Manggar Mahardhika committed
809
            
Muhamad's avatar
Muhamad committed
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
            bangunan = bang.fetchall()
            
            polygon_o = []
            info_polygon = []
            tinggi_pol = []
            for i in bangunan:
                o_pol1 = ''
                o_poly = []
                for x in i[0]['geometry']['coordinates'][0][0]:
                    o_pol1 += (f'{x[0]},{x[1]}""')
                
                o_pol2 = o_pol1.replace('""1',',1')

                o_poly.append(o_pol2.replace('""',''))
                
                polygon_o.append(o_poly)
                tinggi_pol.append(i[0]['administrasi']['f8'])
                info_polygon.append(i[0]['properties']['f1'])
            
        
                
            # for i in batas:
            #     o_batas = ''
            #     o_poly_batas = []
            #     for x in i[0]['geometry']['coordinates'][0][0]:
            #         o_batas += (f'{x[0]},{x[1]}""')
                
            #     o_pol2 = o_pol1.replace('""1',',1')

            #     o_poly.append(o_pol2.replace('""',''))
                
            #     polygon_o.append(o_poly)
            #     tinggi_pol.append(i[0]['administrasi']['f8'])
            #     info_polygon.append(i[0]['properties']['f1'])
        
        lat = json.loads(lat_lng[0][0])['coordinates'][0]
        lng = json.loads(lat_lng[0][0])['coordinates'][1]
                        
        respon={'polygon_o':polygon_o,'tinggi_pol':tinggi_pol, 'info_polygon': info_polygon, 'lat':lat, 'lng':lng, 'line_o':line_o}
        return Response(respon)
Muhamad's avatar
Muhamad committed
850
    
Muhamad's avatar
Muhamad committed
851 852
import random
        
Muhamad's avatar
Muhamad committed
853
@api_view(('POST',))
Muhamad's avatar
Muhamad committed
854
@method_decorator(login_required(login_url='/login/'))
Muhamad's avatar
Muhamad committed
855 856
def editkependudukan(request):
    if request.method == 'POST':
Muhamad's avatar
Muhamad committed
857 858 859 860
        file = request.FILES.get('file')
        coordinate = request.POST.get('coordinate')
        coord_new = json.loads(coordinate)
        
Muhamad's avatar
Muhamad committed
861 862 863 864 865 866 867 868 869
        ketket = ['kelurahan', 'kecamatan', 'kabupaten', 'provinsi', 'luasdesa', 'jumlahpenduduk', 'jumlahkk', 'jumlahlakilaki', 'jumlahperempuan', 'belumkawin', 'kawin', 'ceraihidup', 'ceraimati', 'wajibktp', 'islam', 'kristen', 'katolik', 'hindu', 'budha', 'konghucu', 'kepercayaanlain', 'u0', 'u5', 'u10', 'u15', 'u20', 'u25', 'u30', 'u35', 'u40', 'u45', 'u50', 'u55', 'u60', 'u65', 'u70', 'u75', 'tidaksekolah', 'belumtamat', 'tamatsd', 'tamatsltp', 'tamatslta', 'diplomai', 'diplomaiii', 'diplomaiv', 'strataii', 'strataiii', 'tidakbekerja', 'aparaturpemerintah', 'tenagapendidik', 'wiraswasta', 'pertanian', 'tenagakesehatan', 'pensiunan', 'pegawai', 'tentara', 'kepolisian', 'dosen', 'guru', 'pilot', 'pedagang', 'petani', 'peternak', 'nelayan', 'karyawan', 'buruh', 'pembantu', 'tukang', 'pendeta', 'pastor', 'ustadz', 'pengacara', 'notaris', 'arsitek', 'akuntan', 'dokter', 'bidan', 'perawat', 'psikiater', 'sopir', 'lainnya', 'kodekelurahan']
        
        list_ketek = []
        for i in ketket:
            list_ketek.append(request.POST.get(i))
            # locals()
            
        kelurahan, kecamatan, kabupaten, provinsi, luasdesa, jumlahpenduduk, jumlahkk, jumlahlakilaki, jumlahperempuan, belumkawin, kawin, ceraihidup, ceraimati, wajibktp, islam, kristen, katolik, hindu, budha, konghucu, kepercayaanlain, u0, u5, u10, u15, u20, u25, u30, u35, u40, u45, u50, u55, u60, u65, u70, u75, tidaksekolah, belumtamat, tamatsd, tamatsltp, tamatslta, diplomai, diplomaiii, diplomaiv, strataii, strataiii, tidakbekerja, aparaturpemerintah, tenagapendidik, wiraswasta, pertanian, tenagakesehatan, pensiunan, pegawai, tentara, kepolisian, dosen, guru, pilot, pedagang, petani, peternak, nelayan, karyawan, buruh, pembantu, tukang, pendeta, pastor, ustadz, pengacara, notaris, arsitek, akuntan, dokter, bidan, perawat, psikiater, sopir, lainnya, kodekelurahan = list_ketek
        
Muhamad's avatar
Muhamad committed
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902
        fss = FileSystemStorage(location='static/image/kelurahan/')
        try:
            format = (file.name).split(".")
            num = random.randrange(1, 10000000000000)
            namafile = f"{kelurahan}_{kodekelurahan}_{num}.{format[-1:][0]}"
            filename = fss.save(namafile, file)
            url = fss.url(filename)
        except:
            num = random.randrange(1, 10000000000000)
            namafile = f"{kelurahan}_{kodekelurahan}_{num}.jpg"
            filename = fss.save(namafile, file)
            url = fss.url(filename)
        
        
            
        try:
            with conn.cursor() as buldings:
                buldings.execute("""UPDATE geo_data_kelurahan set geom = st_setsrid(st_geomfromgeojson('{"type":"MultiPolygon", "coordinates":[%s]}'),4326),desa = '%s', kecamatan = '%s', kab_kota = '%s', provinsi = '%s', luas_desa = %s, jumlah_pen = %s, jumlah_kk = %s, pria=%s, wanita = %s, belum_kawin = %s, kawin = %s, cerai_hidup = %s, cerai_mati = %s, wajib_ktp = %s, islam = %s, kristen = %s, khatolik = %s, hindu = %s, budha = %s, konghucu = %s, kepercayaan_lain = %s, u0 = %s, u5 = %s, u10 = %s,u15 = %s, u20 = %s, u25 = %s, u30 = %s, u35 = %s, u40 = %s, u45 = %s, u50 = %s, u55 = %s, u60 = %s, u65 = %s, u70 = %s, u75 = %s, tidak_sekolah = %s, belum_tamat = %s, tamat_sd = %s, sltp = %s, slta = %s, diploma_i = %s, diploma_ii = %s, diploma_iv = %s, strata_ii = %s, strata_iii = %s, tidak_bekerja = %s, aparatur_pemerintah = %s, tenaga_pendidik = %s, wiraswasta = %s, pertanian = %s, tenaga_kesehatan = %s, pensiunan = %s, pegawai = %s, tentara = %s, kepolisian = %s, dosen = %s, guru = %s, pilot = %s, pedagang = %s, petani = %s, peternak = %s, nelayan = %s, karyawan = %s, buruh = %s, pembantu = %s, tukang = %s, pendeta = %s, pastor = %s, ustadz = %s, pengacara = %s, notaris = %s, arsitek = %s, akuntan = %s, dokter = %s, bidan = %s, perawat = %s, psikiater = %s, sopir = %s, lainnya = %s, gambar = '%s' WHERE kode_desa = '%s'"""% (coord_new['geometry']['coordinates'],kelurahan, kecamatan, kabupaten, provinsi, luasdesa,jumlahpenduduk,jumlahkk,jumlahlakilaki,jumlahperempuan,belumkawin,kawin,ceraihidup,ceraimati, wajibktp,islam,kristen,katolik,hindu,budha,konghucu,kepercayaanlain,u0,u5,u10,u15,u20,u25,u30,u35,u40,u45,u50,u55,u60,u65,u70,u75, tidaksekolah, belumtamat, tamatsd, tamatsltp, tamatslta, diplomai, diplomaiii, diplomaiv, strataii, strataiii, tidakbekerja, aparaturpemerintah, tenagapendidik, wiraswasta, pertanian, tenagakesehatan, pensiunan, pegawai, tentara, kepolisian, dosen, guru, pilot, pedagang, petani, peternak, nelayan, karyawan, buruh, pembantu, tukang, pendeta, pastor, ustadz, pengacara, notaris, arsitek, akuntan, dokter, bidan, perawat, psikiater, sopir, lainnya, namafile, kodekelurahan))
            conn.commit()
            
            with conn.cursor() as kependuduk:
                kependuduk.execute("""SELECT kode_desa, desa, kecamatan, kab_kota, provinsi, luas_desa, jumlah_pen, jumlah_kk, 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, 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, dosen, guru, pilot, pedagang, petani, peternak, nelayan, karyawan, buruh, pembantu, tukang, pendeta, pastor, ustadz, pengacara, notaris, arsitek, akuntan, dokter, bidan, perawat, psikiater, sopir, lainnya, gambar FROM geo_data_kelurahan WHERE kode_desa = '%s'"""% kodekelurahan)
                data_kependuduk = kependuduk.fetchall()      
                     
            data = 'SUCCESS'
            info = 'data telah diperbaharui'
            status = 0
        except:
            data = 'NOT SUCCESS'
            info = 'Hubungi Orang Server'
            status = 1
            
        respon={'data':data, 'info':info, 'code':status, 'penduduk':data_kependuduk[0]}
Muhamad's avatar
Muhamad committed
903
        data = data_kependuduk[0]
Muhamad's avatar
Muhamad committed
904
        return Response(respon)
Muhamad's avatar
Muhamad committed
905 906 907

@api_view(('POST',))
def editrumahsakit(request):
Manggar Mahardhika's avatar
Manggar Mahardhika committed
908 909
    idrs = request.POST.get('idrs')
    namars = request.POST.get('namobj')
Muhamad's avatar
Muhamad committed
910 911
    remark = request.POST.get('remark')
    luastanah = request.POST.get('luastanah')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
912 913
    gambar = request.POST.get('gambar')
    alamat = request.POST.get('alamat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
914
    if alamat is None:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
915 916 917
        alamat = 'alamat'
    elif alamat == '':
        alamat = 'alamat'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
918 919
    else:
        alamat = request.POST.get('alamat')
Muhamad's avatar
Muhamad committed
920
    perangkat = request.POST.get('perangkat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
921
    if perangkat is None:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
922 923 924
        perangkat = 'bpk'
    elif perangkat == '':
        perangkat = 'bpk'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
925 926 927 928 929 930 931
    else:
        perangkat = request.POST.get('perangkat')
    
    point = request.POST.get("point")
    cood_edit = json.loads(point)
        
    co_edit = cood_edit['geometry']['coordinates']
Muhamad's avatar
Muhamad committed
932
    
Manggar Mahardhika's avatar
Manggar Mahardhika committed
933 934 935 936 937 938 939 940 941 942
    file = request.FILES.get('file')
    fss = FileSystemStorage(location='static/img/image/')
    try:
        format = (file.name).split(".")
        num = random.randrange(1, 10000000000000)
        namafile = f"{namars}_{num}.{format[-1:][0]}"
        filename = fss.save(namafile, file)
        # print(file.name)
        url = fss.url(filename)
    except:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
943
        namafile = gambar
Manggar Mahardhika's avatar
Manggar Mahardhika committed
944
    
Muhamad's avatar
Muhamad committed
945
    with conn.cursor() as editrs:
946
        editrs.execute("""update geo_rumah_sakit set geom = st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), namobj = '%s', alamat = '%s', remark = '%s', luas_tanah = '%s', perangkat = '%s', gambar = '%s' where id = %s"""%(co_edit, namars, alamat, remark, luastanah, perangkat, namafile, idrs))
Muhamad's avatar
Muhamad committed
947 948 949
    conn.commit()    
    
    with conn.cursor() as hasledit:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
950
        hasledit.execute("SELECT id, namobj, alamat, remark, luas_bangunan, luas_tanah, tinggi_bangunan, perangkat, gambar, json_build_object('type', 'Feature', 'geometry', ST_AsGeoJSON(geom :: geometry) :: json) from geo_rumah_sakit where id = %s"% idrs)
Muhamad's avatar
Muhamad committed
951 952
        hasil_editrs = hasledit.fetchall()
    
953 954 955 956 957 958
    data = {'status':'Success'}
    data = 'SUCCESS'
    info = 'data telah diperbaharui'
    status = 0
    respon={'data':data, 'info': info, 'status':status}
    return Response(respon)
Muhamad's avatar
Muhamad committed
959 960 961

@api_view(('POST',))
def editcagarbudaya(request):
Manggar Mahardhika's avatar
Manggar Mahardhika committed
962
    idcagar = request.POST.get('idcb')
Muhamad's avatar
Muhamad committed
963 964 965 966 967
    namobj = request.POST.get('namobj')
    luas = request.POST.get('luas')
    remark = request.POST.get('remark')
    gambar = request.POST.get('gambar')
    alamat = request.POST.get('alamat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
968 969 970 971 972 973
    if alamat is None:
        alamat = 'alamat'
    elif alamat == '':
        alamat = 'alamat'
    else:
        alamat = request.POST.get('alamat')
Muhamad's avatar
Muhamad committed
974
    perangkat = request.POST.get('perangkat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996
    if perangkat is None:
        perangkat = 'bpk'
    elif perangkat == '':
        perangkat = 'bpk'
    else:
        perangkat = request.POST.get('perangkat')
        
    point = request.POST.get("point")
    cood_edit = json.loads(point)
        
    co_edit = cood_edit['geometry']['coordinates']
    
    file = request.FILES.get('file')
    fss = FileSystemStorage(location='static/img/image/')
    try:
        format = (file.name).split(".")
        num = random.randrange(1, 10000000000000)
        namafile = f"{namobj}_{num}.{format[-1:][0]}"
        filename = fss.save(namafile, file)
        # print(file.name)
        url = fss.url(filename)
    except:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
997
        namafile = gambar
Muhamad's avatar
Muhamad committed
998 999
    
    with conn.cursor() as editcagar:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1000
        editcagar.execute("""update geo_cagar_budaya set geom = st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), namobj = '%s', alamat = '%s', remark = '%s', luas = '%s', perangkat = '%s', gambar = '%s' where id = %s"""% (co_edit, namobj, alamat, remark, luas, perangkat, namafile, idcagar))
Muhamad's avatar
Muhamad committed
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
    conn.commit()    
    
    with conn.cursor() as hasiledit:
        hasiledit.execute("""select namobj, alamat, remark, luas, gambar, perangkat from geo_cagar_budaya where id = %s"""% idcagar)
        hasileditcagar = hasiledit.fetchall()
    
    data = hasileditcagar[0]
    return Response(data)

@api_view(('POST',))
def editkantoradmin(request):
    idkantor = request.POST.get('id')
    namobj = request.POST.get('namobj')
    remark = request.POST.get('remark')
    luat_tanah = request.POST.get('luastanah')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1016
    gambar = request.POST.get('gambar')
Muhamad's avatar
Muhamad committed
1017
    alamat = request.POST.get('alamat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1018
    if alamat is None:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1019 1020 1021
        alamat = 'alamat'
    elif alamat == '':
        alamat = 'alamat'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1022 1023
    else:
        alamat = request.POST.get('alamat')
Muhamad's avatar
Muhamad committed
1024
    perangkat = request.POST.get('perangkat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1025
    if perangkat is None:
1026
        perangkat = 'Bpk'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1027
    elif perangkat == '':
1028
        perangkat = 'Bpk'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1029 1030 1031 1032 1033 1034 1035
    else:
        perangkat = request.POST.get('perangkat')
    
    point = request.POST.get("point")
    cood_edit = json.loads(point)
        
    co_edit = cood_edit['geometry']['coordinates']
Muhamad's avatar
Muhamad committed
1036

Manggar Mahardhika's avatar
Manggar Mahardhika committed
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
    file = request.FILES.get('file')
    fss = FileSystemStorage(location='static/img/image/')
    try:
        format = (file.name).split(".")
        num = random.randrange(1, 10000000000000)
        namafile = f"{namobj}_{num}.{format[-1:][0]}"
        filename = fss.save(namafile, file)
        # print(file.name)
        url = fss.url(filename)
    except:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1047
        namafile = gambar
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1048

Manggar Mahardhika's avatar
Manggar Mahardhika committed
1049
    with conn.cursor() as editka:
1050
        editka.execute("""update geo_kantor_administrasi set geom = st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), namobj = '%s',  remark = '%s', luas_tanah = %s, perangkat = '%s', alamat = '%s', gambar = '%s' where id = %s"""%(co_edit, namobj, remark, luat_tanah, perangkat, alamat, namafile, idkantor))
1051
    conn.commit()
Muhamad's avatar
Muhamad committed
1052
    
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
    data = {'status':'Success'}
    data = 'SUCCESS'
    info = 'data telah diperbaharui'
    status = 0
    respon={'data':data, 'info': info, 'status':status}
    return Response(respon)

@api_view(('POST',))
def deletekantoradmin(request):
    idkantor = request.POST.get('id')
    try:
        with conn.cursor() as editka:
            editka.execute("""update geo_kantor_administrasi set is_deleted = 1 where id = %s"""%(idkantor))
        conn.commit()    
        
        
        data = {'status':'Success'}
        data = 'SUCCESS'
        info = 'data telah diperbaharui'
        status = 0
    except:
        data = 'Sorry'
        info = 'Dalam Perbaikan'
        status = 1
Muhamad's avatar
Muhamad committed
1077
    
1078 1079
    respon={'data':data, 'info': info, 'status':status}
    return Response(respon)
Muhamad's avatar
Muhamad committed
1080

Manggar Mahardhika's avatar
Manggar Mahardhika committed
1081 1082 1083 1084 1085 1086
@api_view(('POST',))
def editlayanankesehatan(request):
    idlakes = request.POST.get('id')
    namobj = request.POST.get('namobj')
    remark = request.POST.get('remark')
    luat_tanah = request.POST.get('luastanah')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1087
    gambar = request.POST.get('gambar')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1088 1089
    alamat = request.POST.get('alamat')
    if alamat is None:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1090 1091 1092
        alamat = 'alamat'
    elif alamat == '':
        alamat = 'alamat'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1093 1094 1095 1096
    else:
        alamat = request.POST.get('alamat')
    perangkat = request.POST.get('perangkat')
    if perangkat is None:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1097 1098 1099
        perangkat = 'bpk'
    elif perangkat == '':
        perangkat = 'bpk'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1100 1101 1102 1103 1104 1105 1106 1107
    else:
        perangkat = request.POST.get('perangkat')
    
    point = request.POST.get("point")
    cood_edit = json.loads(point)
        
    co_edit = cood_edit['geometry']['coordinates']

Manggar Mahardhika's avatar
Manggar Mahardhika committed
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
    file = request.FILES.get('file')
    fss = FileSystemStorage(location='static/img/image/')
    try:
        format = (file.name).split(".")
        num = random.randrange(1, 10000000000000)
        namafile = f"{namobj}_{num}.{format[-1:][0]}"
        filename = fss.save(namafile, file)
        # print(file.name)
        url = fss.url(filename)
    except:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1118
        namafile = gambar
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1119
    
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1120
    with conn.cursor() as editka:
1121
        editka.execute("""update geo_layanan_kesehatan set geom = st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), namobj = '%s',  remark = '%s', luas_tanah = %s, perangkat = '%s', alamat = '%s', gambar = '%s' where id = %s"""%(co_edit, namobj, remark, luat_tanah, perangkat, alamat, namafile, idlakes))
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1122 1123 1124 1125 1126 1127
    conn.commit()    
    
    with conn.cursor() as hasiledit:
        hasiledit.execute("""select namobj,  remark, luas_bangunan, luas_tanah, tinggi_bangunan, perangkat, gambar, alamat from geo_layanan_kesehatan where id = %s"""% idlakes)
        hasileditkantor = hasiledit.fetchall()
    
1128 1129 1130 1131 1132 1133
    data = {'status':'Success'}
    data = 'SUCCESS'
    info = 'data telah diperbaharui'
    status = 0
    respon={'data':data, 'info': info, 'status':status}
    return Response(respon)
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1134

Muhamad's avatar
Muhamad committed
1135 1136
@api_view(('POST',))
def editpuskesmas(request):
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1137
    idpus = request.POST.get('idpus')
Muhamad's avatar
Muhamad committed
1138 1139 1140
    namobj = request.POST.get('namobj')
    remark = request.POST.get('remark')
    luat_tanah = request.POST.get('luastanah')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1141
    gambar = request.POST.get('gambar')
Muhamad's avatar
Muhamad committed
1142
    alamat = request.POST.get('alamat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1143
    if alamat is None:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1144 1145 1146
        alamat = 'alamat'
    elif alamat == '':
        alamat = 'alamat'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1147 1148
    else:
        alamat = request.POST.get('alamat')
Muhamad's avatar
Muhamad committed
1149
    perangkat = request.POST.get('perangkat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1150
    if perangkat is None:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1151 1152 1153
        perangkat = 'bpk'
    elif perangkat == '':
        perangkat = 'bpk'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1154 1155 1156 1157 1158 1159 1160
    else:
        perangkat = request.POST.get('perangkat')
    
    point = request.POST.get("point")
    cood_edit = json.loads(point)
        
    co_edit = cood_edit['geometry']['coordinates']
Muhamad's avatar
Muhamad committed
1161

Manggar Mahardhika's avatar
Manggar Mahardhika committed
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171
    file = request.FILES.get('file')
    fss = FileSystemStorage(location='static/img/image/')
    try:
        format = (file.name).split(".")
        num = random.randrange(1, 10000000000000)
        namafile = f"{namobj}_{num}.{format[-1:][0]}"
        filename = fss.save(namafile, file)
        # print(file.name)
        url = fss.url(filename)
    except:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1172
        namafile = gambar
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1173

Muhamad's avatar
Muhamad committed
1174
    with conn.cursor() as editrs:
1175
        editrs.execute("""update geo_puskesmas set geom = st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), namobj = '%s', remark = '%s', luas_tanah = '%s', perangkat = '%s', alamat = '%s', gambar = '%s' where id = %s"""%(co_edit, namobj, remark, luat_tanah, perangkat, alamat, namafile, idpus))
Muhamad's avatar
Muhamad committed
1176 1177 1178 1179 1180 1181
    conn.commit()    
    
    with conn.cursor() as hasiledit:
        hasiledit.execute("""select namobj,  remark, luas_bangunan, luas_tanah, tinggi_bangunan, perangkat, gambar, alamat from geo_puskesmas where id = %s"""% idpus)
        hasileditkantor = hasiledit.fetchall()
    
1182 1183 1184 1185 1186 1187
    data = {'status':'Success'}
    data = 'SUCCESS'
    info = 'data telah diperbaharui'
    status = 0
    respon={'data':data, 'info': info, 'status':status}
    return Response(respon)
Muhamad's avatar
Muhamad committed
1188 1189 1190

@api_view(('POST',))
def editibadah(request):
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1191
    idsarib = request.POST.get('idsi')
Muhamad's avatar
Muhamad committed
1192 1193 1194
    namobj = request.POST.get('namobj')
    remark = request.POST.get('remark')
    luat_tanah = request.POST.get('luastanah')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1195
    gambar = request.POST.get('gambar')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1196 1197
    alamat = request.POST.get('alamat')
    perangkat = request.POST.get('perangkat')
Muhamad's avatar
Muhamad committed
1198
    alamat = request.POST.get('alamat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1199
    if alamat is None:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1200 1201 1202
        alamat = 'alamat'
    elif alamat == '':
        alamat = 'alamat'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1203 1204
    else:
        alamat = request.POST.get('alamat')
Muhamad's avatar
Muhamad committed
1205
    perangkat = request.POST.get('perangkat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1206
    if perangkat is None:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1207 1208 1209
        perangkat = 'bpk'
    elif perangkat == '':
        perangkat = 'bpk'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1210 1211 1212 1213 1214 1215 1216
    else:
        perangkat = request.POST.get('perangkat')
    
    point = request.POST.get("point")
    cood_edit = json.loads(point)
        
    co_edit = cood_edit['geometry']['coordinates']
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227
    
    file = request.FILES.get('file')
    fss = FileSystemStorage(location='static/img/image/')
    try:
        format = (file.name).split(".")
        num = random.randrange(1, 10000000000000)
        namafile = f"{namobj}_{num}.{format[-1:][0]}"
        filename = fss.save(namafile, file)
        # print(file.name)
        url = fss.url(filename)
    except:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1228
        namafile = gambar
Muhamad's avatar
Muhamad committed
1229 1230

    with conn.cursor() as editrs:
1231
        editrs.execute("""update geo_sarana_ibadah set geom = st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), namobj = '%s',  remark = '%s', luas_tanah = '%s', perangkat = '%s', alamat = '%s', gambar = '%s' where id = %s"""%(co_edit, namobj, remark, luat_tanah, perangkat, alamat, namafile, idsarib))
Muhamad's avatar
Muhamad committed
1232 1233 1234 1235 1236 1237
    conn.commit()    
    
    with conn.cursor() as hasiledit:
        hasiledit.execute("""select namobj,  remark, luas_bangunan, luas_tanah, tinggi_bangunan, perangkat, gambar, alamat from geo_sarana_ibadah where id = %s"""% idsarib)
        hasileditkantor = hasiledit.fetchall()
    
1238 1239 1240 1241 1242 1243
    data = {'status':'Success'}
    data = 'SUCCESS'
    info = 'data telah diperbaharui'
    status = 0
    respon={'data':data, 'info': info, 'status':status}
    return Response(respon)
Muhamad's avatar
Muhamad committed
1244 1245 1246

@api_view(('POST',))
def editsekolah(request):
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1247
    idsekolah = request.POST.get('idsp')
Muhamad's avatar
Muhamad committed
1248 1249 1250
    namobj = request.POST.get('namobj')
    remark = request.POST.get('remark')
    luat_tanah = request.POST.get('luastanah')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1251
    gambar = request.POST.get('gambar')
Muhamad's avatar
Muhamad committed
1252
    alamat = request.POST.get('alamat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1253
    if alamat is None:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1254 1255 1256
        alamat = 'alamat'
    elif alamat == '':
        alamat = 'alamat'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1257 1258
    else:
        alamat = request.POST.get('alamat')
Muhamad's avatar
Muhamad committed
1259
    perangkat = request.POST.get('perangkat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1260
    if perangkat is None:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1261 1262 1263
        perangkat = 'bpk'
    elif perangkat == '':
        perangkat = 'bpk'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1264 1265 1266 1267 1268 1269 1270
    else:
        perangkat = request.POST.get('perangkat')
    
    point = request.POST.get("point")
    cood_edit = json.loads(point)
        
    co_edit = cood_edit['geometry']['coordinates']
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
    
    file = request.FILES.get('file')
    fss = FileSystemStorage(location='static/img/image/')
    try:
        format = (file.name).split(".")
        num = random.randrange(1, 10000000000000)
        namafile = f"{namobj}_{num}.{format[-1:][0]}"
        filename = fss.save(namafile, file)
        # print(file.name)
        url = fss.url(filename)
    except:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1282
        namafile = gambar
Muhamad's avatar
Muhamad committed
1283 1284

    with conn.cursor() as editrs:
1285
        editrs.execute("""update geo_sarana_pendidikan set geom = st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), namobj = '%s',  remark = '%s', luas_tanah = '%s', perangkat = '%s', alamat = '%s', gambar = '%s' where id = %s"""%(co_edit, namobj, remark, luat_tanah, perangkat, alamat, namafile, idsekolah))
Muhamad's avatar
Muhamad committed
1286 1287 1288 1289 1290 1291 1292 1293
    conn.commit()    
    
    with conn.cursor() as hasiledit:
        hasiledit.execute("""select namobj,  remark, luas_bangunan, luas_tanah, tinggi_bangunan, perangkat, gambar, alamat from geo_sarana_ibadah where id = %s"""% idsekolah)
        hasileditkantor = hasiledit.fetchall()
    
    data = hasileditkantor[0]

1294 1295 1296 1297 1298 1299
    data = {'status':'Success'}
    data = 'SUCCESS'
    info = 'data telah diperbaharui'
    status = 0
    respon={'data':data, 'info': info, 'status':status}
    return Response(respon)
Muhamad's avatar
Muhamad committed
1300 1301 1302

@api_view(('POST',))
def editspbu(request):
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1303
    idspbu = request.POST.get('idspbu')
Muhamad's avatar
Muhamad committed
1304 1305 1306 1307 1308
    namobj = request.POST.get('namobj')
    remark = request.POST.get('remark')
    luas_bangunan = request.POST.get('luasbangunan')
    luat_tanah = request.POST.get('luastanah')
    tinggi_bangunan = request.POST.get('tinggibangunan')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1309
    gambar = request.POST.get('gambar')
Muhamad's avatar
Muhamad committed
1310
    alamat = request.POST.get('alamat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1311 1312
    if alamat is None:
        alamat = 'alamat'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1313 1314
    elif alamat == '':
        alamat = 'alamat'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1315 1316
    else:
        alamat = request.POST.get('alamat')
Muhamad's avatar
Muhamad committed
1317
    perangkat = request.POST.get('perangkat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1318 1319
    if perangkat is None:
        perangkat = 'bpk'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1320 1321
    elif perangkat == '':
        perangkat = 'bpk'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1322 1323 1324 1325 1326 1327 1328
    else:
        perangkat = request.POST.get('perangkat')

    point = request.POST.get("point")
    cood_edit = json.loads(point)
        
    co_edit = cood_edit['geometry']['coordinates']
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339
    
    file = request.FILES.get('file')
    fss = FileSystemStorage(location='static/img/image/')
    try:
        format = (file.name).split(".")
        num = random.randrange(1, 10000000000000)
        namafile = f"{namobj}_{num}.{format[-1:][0]}"
        filename = fss.save(namafile, file)
        # print(file.name)
        url = fss.url(filename)
    except:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1340
        namafile = gambar
Muhamad's avatar
Muhamad committed
1341 1342

    with conn.cursor() as editrs:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1343
        editrs.execute("""update geo_spbu set geom = st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), namobj = '%s',  remark = '%s', luas_bangunan = '%s', luas_tanah = '%s', tinggi_bangunan = '%s', perangkat = '%s', alamat = '%s', gambar = '%s' where id = %s"""%(co_edit, namobj, remark, luas_bangunan, luat_tanah, tinggi_bangunan, perangkat, alamat, namafile, idspbu))
Muhamad's avatar
Muhamad committed
1344 1345 1346
    conn.commit()    
    
    with conn.cursor() as hasiledit:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1347
        hasiledit.execute("""select namobj,  remark, luas_bangunan, luas_tanah, tinggi_bangunan, perangkat, gambar, alamat from geo_spbu where id = %s"""% idspbu)
Muhamad's avatar
Muhamad committed
1348 1349 1350 1351 1352 1353 1354 1355
        hasileditkantor = hasiledit.fetchall()
    
    data = hasileditkantor[0]

    return Response(data)

@api_view(('POST',))
def editstasiun(request):
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1356
    idstasiun = request.POST.get('idst')
Muhamad's avatar
Muhamad committed
1357 1358 1359 1360 1361
    namobj = request.POST.get('namobj')
    remark = request.POST.get('remark')
    luas_bangunan = request.POST.get('luasbangunan')
    luat_tanah = request.POST.get('luastanah')
    tinggi_bangunan = request.POST.get('tinggibangunan')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1362
    gambar = request.POST.get('gambar')
Muhamad's avatar
Muhamad committed
1363
    alamat = request.POST.get('alamat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1364 1365
    if alamat is None:
        alamat = 'alamat'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1366 1367
    elif alamat == '':
        alamat = 'alamat'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1368 1369
    else:
        alamat = request.POST.get('alamat')
Muhamad's avatar
Muhamad committed
1370
    perangkat = request.POST.get('perangkat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1371 1372
    if perangkat is None:
        perangkat = 'bpk'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1373 1374
    elif perangkat == '':
        perangkat = 'bpk'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1375 1376 1377 1378 1379 1380 1381
    else:
        perangkat = request.POST.get('perangkat')

    point = request.POST.get("point")
    cood_edit = json.loads(point)
        
    co_edit = cood_edit['geometry']['coordinates']
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392
    
    file = request.FILES.get('file')
    fss = FileSystemStorage(location='static/img/image/')
    try:
        format = (file.name).split(".")
        num = random.randrange(1, 10000000000000)
        namafile = f"{namobj}_{num}.{format[-1:][0]}"
        filename = fss.save(namafile, file)
        # print(file.name)
        url = fss.url(filename)
    except:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1393
        namafile = gambar
Muhamad's avatar
Muhamad committed
1394 1395

    with conn.cursor() as editrs:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1396
        editrs.execute("""update geo_stasiun set geom = st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), namobj = '%s',  remark = '%s', luas_bangunan = '%s', luas_tanah = '%s', tinggi_bangunan = '%s', perangkat = '%s', alamat = '%s', gambar = '%s' where id = %s"""%(co_edit, namobj, remark, luas_bangunan, luat_tanah, tinggi_bangunan, perangkat, alamat, namafile, idstasiun))
Muhamad's avatar
Muhamad committed
1397 1398 1399
    conn.commit()    
    
    with conn.cursor() as hasiledit:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1400
        hasiledit.execute("""select namobj,  remark, luas_bangunan, luas_tanah, tinggi_bangunan, perangkat, gambar, alamat from geo_stasiun where id = %s"""% idstasiun)
Muhamad's avatar
Muhamad committed
1401 1402 1403 1404 1405 1406 1407 1408
        hasileditkantor = hasiledit.fetchall()
    
    data = hasileditkantor[0]

    return Response(data)

@api_view(('POST',))
def editterminal(request):
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1409 1410 1411 1412
    idterm = request.POST.get('idtr')
    namobj = request.POST.get('namobj')
    remark = request.POST.get('remark')
    luas = request.POST.get('luas')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1413
    gambar = request.POST.get('gambar')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1414 1415 1416
    alamat = request.POST.get('alamat')
    if alamat is None:
        alamat = 'alamat'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1417 1418
    elif alamat == '':
        alamat = 'alamat'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1419 1420
    else:
        alamat = request.POST.get('alamat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1421
        
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1422 1423 1424
    perangkat = request.POST.get('perangkat')
    if perangkat is None:
        perangkat = 'bpk'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1425 1426
    elif perangkat == '':
        perangkat = 'bpk'
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1427 1428 1429 1430 1431 1432 1433
    else:
        perangkat = request.POST.get('perangkat')

    point = request.POST.get("point")
    cood_edit = json.loads(point)
        
    co_edit = cood_edit['geometry']['coordinates']
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444
    
    file = request.FILES.get('file')
    fss = FileSystemStorage(location='static/img/image/')
    try:
        format = (file.name).split(".")
        num = random.randrange(1, 10000000000000)
        namafile = f"{namobj}_{num}.{format[-1:][0]}"
        filename = fss.save(namafile, file)
        # print(file.name)
        url = fss.url(filename)
    except:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1445
        namafile = gambar
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1446 1447

    with conn.cursor() as editrs:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1448
        editrs.execute("""update geo_terminal_bus set geom = st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), namobj = '%s',  remark = '%s', luas = '%s', perangkat = '%s', alamat = '%s', gambar = '%s' where id = %s"""%(co_edit, namobj, remark, luas, perangkat, alamat, namafile, idterm))
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461
    conn.commit()    
    
    with conn.cursor() as hasiledit:
        hasiledit.execute("""select namobj, remark, luas, perangkat, gambar, alamat from geo_terminal_bus where id = %s"""% idterm)
        hasileditkantor = hasiledit.fetchall()
    
    data = hasileditkantor[0]

    return Response(data)

@api_view(('POST',))
def editgardu(request):
    idgardu = request.POST.get('idgl')
Muhamad's avatar
Muhamad committed
1462 1463 1464 1465 1466
    namobj = request.POST.get('namobj')
    remark = request.POST.get('remark')
    luas_bangunan = request.POST.get('luasbangunan')
    luat_tanah = request.POST.get('luastanah')
    tinggi_bangunan = request.POST.get('tinggibangunan')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1467
    gambar = request.POST.get('gambar')
Muhamad's avatar
Muhamad committed
1468
    alamat = request.POST.get('alamat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1469 1470 1471 1472
    if alamat is None:
        alamat = 'alamat'
    else:
        alamat = request.POST.get('alamat')
Muhamad's avatar
Muhamad committed
1473
    perangkat = request.POST.get('perangkat')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1474 1475 1476 1477 1478 1479 1480 1481 1482
    if perangkat is None:
        perangkat = 'bpk'
    else:
        perangkat = request.POST.get('perangkat')

    point = request.POST.get("point")
    cood_edit = json.loads(point)
        
    co_edit = cood_edit['geometry']['coordinates']
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493
    
    file = request.FILES.get('file')
    fss = FileSystemStorage(location='static/img/image/')
    try:
        format = (file.name).split(".")
        num = random.randrange(1, 10000000000000)
        namafile = f"{namobj}_{num}.{format[-1:][0]}"
        filename = fss.save(namafile, file)
        # print(file.name)
        url = fss.url(filename)
    except:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1494
        namafile = gambar
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1495

Muhamad's avatar
Muhamad committed
1496 1497

    with conn.cursor() as editrs:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1498
        editrs.execute("""update geo_gardu_listrik set geom = st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), namobj = '%s',  remark = '%s', luas_bangunan = '%s', luas_tanah = '%s', tinggi_bangunan = '%s', perangkat = '%s', alamat = '%s', gambar = '%s' where id = %s"""%(co_edit, namobj, remark, luas_bangunan, luat_tanah, tinggi_bangunan, perangkat, alamat, namafile, idgardu))
Muhamad's avatar
Muhamad committed
1499 1500 1501
    conn.commit()    
    
    with conn.cursor() as hasiledit:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1502
        hasiledit.execute("""select namobj, remark, luas_bangunan, luas_tanah, tinggi_bangunan, perangkat, gambar, alamat from geo_gardu_listrik where id = %s"""% idgardu)
Muhamad's avatar
Muhamad committed
1503 1504 1505 1506 1507 1508
        hasileditkantor = hasiledit.fetchall()
    
    data = hasileditkantor[0]

    return Response(data)

Muhamad's avatar
Muhamad committed
1509 1510
@api_view(('GET',))
@group_required(('Dinas Pekerjaan Umum dan Penataan Ruang', 'Dinas Perumahan dan Kawasan Permukiman', 'Dinas Lingkungan Hidup'), login_url='/')
Muhamad's avatar
Muhamad committed
1511
def edittuplah(request):
Muhamad's avatar
Muhamad committed
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534
    idtuplah = request.GET.get('idtuplah')

    try:
        with conn.cursor() as desa:
            desa.execute(f"SELECT json_build_object('type', 'Feature', 'legend', (a.id, a.legenda, st_area(a.geom::geography), a.gambar) ,'geometry', ST_AsGeoJSON( st_intersection(a.geom, b.geom):: geometry) :: json) from geo_tuplah a, geo_prov_kab b where a.id=%s"% idtuplah)
            all = desa.fetchall()    
            
        data = 'SUCCESS'
        info = 'data telah diperbaharui'
        status = 0
    except:
        data = 'Sorry'
        info = 'Anda Dilarang Akses Link ini'
        status = 1
        
    respon = {
        'data':data, 
        'info':info, 
        'code':status,
        'tuplah':all[0][0]
    }
        
    return Response(respon)
Muhamad's avatar
Muhamad committed
1535 1536

@api_view(('POST',))
Muhamad's avatar
Muhamad committed
1537 1538
@group_required(('Dinas Pekerjaan Umum dan Penataan Ruang', 'Dinas Perumahan dan Kawasan Permukiman', 'Dinas Lingkungan Hidup'),login_url='/')
def edittuplahvalid(request):
Muhamad's avatar
Muhamad committed
1539
    file = request.FILES.get('file')
Muhamad's avatar
Muhamad committed
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608
    idtuplah = request.POST.get('idtuplah')
    cordi = request.POST.get('cord')
    cord = json.loads(cordi)
    
    fss = FileSystemStorage(location='static/image/tuplah/')
    try:
        format = (file.name).split(".")
        num = random.randrange(1, 10000000000000)
        namafile = f"{idtuplah}_{num}.{format[-1:][0]}"
        filename = fss.save(namafile, file)
        url = fss.url(filename)
    except:
        namafile = "NONE"
        
    try:
        with conn.cursor() as desa:
            desa.execute("""UPDATE geo_tuplah set geom = st_setsrid(st_geomfromgeojson('{"type":"MultiPolygon", "coordinates":[[%s]]}'),4326), gambar = '%s' where id=%s"""%(cord['geometry']['coordinates'][0], namafile, int(idtuplah)))
        conn.commit()
            
        data = 'SUCCESS'
        info = 'data telah diperbaharui'
        status = 0
    except:
        data = 'Sorry'
        info = 'Hubungi Developer'
        status = 1
        
    
    
    respon={'data':data, 'info':info, 'code':status}
    return Response(respon)

@api_view(('GET',))
def maps3d(request):
    lattt = request.GET.get('latt')
    longg = request.GET.get('loog')
    
    print(lattt, type(longg))
    with conn.cursor() as gp3:
        gp3.execute("""select json_build_object('type', 'Feature', 'properties', (id, name, information), 'administrasi',(address_1, address_2, address_3, provinsi, alamat, luas_bangunan, luas_tanah, tinggi_bangunan, gambar, pemilik), 'geometry', ST_AsGeoJSON(geom :: geometry) :: json) from geo_bangunan WHERE ST_DistanceSphere(geom, ST_MakePoint(%s,%s)) <= 400 LIMIT 1000"""%(float(longg), float(lattt)))
        polygon_buildings = gp3.fetchall()
        
        polygon_o = []
        info_polygon = []
        tinggi_pol = []
        for i in polygon_buildings:
            o_pol1 = ''
            o_poly = []
            for x in i[0]['geometry']['coordinates'][0][0]:
                o_pol1 += (f'{x[0]},{x[1]}""')
            
            o_pol2 = o_pol1.replace('""1',',1')

            o_poly.append(o_pol2.replace('""',''))
            
            polygon_o.append(o_poly)
            tinggi_pol.append(i[0]['administrasi']['f8'])
            info_polygon.append(i[0]['properties']['f1']) 
                    
    respon={'polygon_o':polygon_o,'tinggi_pol':tinggi_pol, 'info_polygon': info_polygon}
    return Response(respon)

@api_view(('GET',))
def createbang(request):
    poly_create = request.GET.get('polygon')
    p_create = poly_create.replace('"','')
    po_create = p_create.replace(', ','],[')
    
    name = request.GET.get('name')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1609 1610 1611
    tipedb = request.GET.get('tipedb')
    poin = request.GET.get('poin')
    remark = request.GET.get('remark')
Muhamad's avatar
Muhamad committed
1612
    info = request.GET.get('info')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1613
    atalam = request.GET.get('alamat')
Muhamad's avatar
Muhamad committed
1614 1615
    lb = request.GET.get('lb')
    lt = request.GET.get('lt')
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1616 1617 1618
    tibang = request.GET.get('tb')
    ltbang = request.GET.get('ltb')
    kilimep = request.GET.get('pemilik')
Muhamad's avatar
Muhamad committed
1619 1620 1621
    namafile = "None"
    
    latlng = po_create.split("],[")[0]
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1622 1623
    print(p_create)
    print(latlng)
Muhamad's avatar
Muhamad committed
1624
    
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1625 1626 1627 1628
    if name == "":
        name = "None"
    else:
        name = name
Muhamad's avatar
Muhamad committed
1629
        
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644
    if info == "":
        info = "None"
    else:
        info = info
        
    if lb == "":
        lb = 0
    else:
        lb = lb
        
    if lt == "":
        lt = 0
    else:
        lt = lt
    
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1645 1646 1647 1648 1649 1650 1651 1652 1653
    if tipedb == "":
        tdb = "bangunan"
    else:
        tdb = tipedb
    
    if poin == "":
        pointopeto = 0
    else:
        pointopeto = poin
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1654
    
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1655 1656 1657 1658
    if remark == "":
        rem = "bangunan"
    else:
        rem = remark
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672
    
    if atalam == "":
        alamat = "None"
    else:
        alamat = atalam
    print(alamat)
    try:
        if tibang == "" and ltbang != "":
            tb = ltbang*3
        elif tibang == "" and ltbang == "":
            tb = 0
            ltb = 0
        else:
            tb = tibang
Muhamad's avatar
Muhamad committed
1673
    except:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700
        tb = 0
    print(tb)
    try:
        if ltbang == "" and tibang != "":
            ltb = int(int(tibang)/3)
        elif tibang == "" and ltbang == "":
            tb = 0
            ltb = 0
        else:
            ltb = ltbang
    except:
        ltb = 0
    if kilimep == "":
        pemilik = "unnamed"
    else:
        pemilik = kilimep
    print(pemilik)
    
    
    # try:
    with conn.cursor() as kel:
        kel.execute("SELECT desa, kecamatan, kab_kota, provinsi FROM geo_data_kelurahan WHERE st_intersects(geom, 'SRID=4326;POINT(%s)'::geometry)"% latlng)
        adm = kel.fetchall()
        
    administrasi = adm[0]
            
    with conn.cursor() as buldings:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1701
        buldings.execute("""INSERT INTO geo_bangunan(geom, name, information, sumber, alamat, address_1, address_2, address_3, provinsi, no, luas_bangunan, luas_tanah, tinggi_bangunan, lantai, gambar, pemilik, point_id, type_id, remark, db_tipe) VALUES (ST_GeomFromEWKT('SRID=0;MULTIPOLYGON(((%s)))'), '%s', '%s', 'new', '%s', '%s', '%s', '%s', '%s', '0', '%s', '%s', '%s', '%s', '%s', '%s', %s, '1', '%s', '%s')"""% (p_create, name, info, alamat, administrasi[0], administrasi[1], administrasi[2], administrasi[3], lb, lt, tb, ltb, namafile, pemilik, pointopeto, rem, tdb ))
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
    conn.commit()
    data = {'status':'Success'}
    
    data = 'SUCCESS'
    info = 'data telah diperbaharui'
    status = 0
    # except:
    #     data = 'Sorry'
    #     info = 'Dalam Perbaikan'
    #     status = 1
Muhamad's avatar
Muhamad committed
1712 1713 1714 1715
    
    respon={'data':data, 'info': info, 'status':status}
    return Response(respon)

Manggar Mahardhika's avatar
Manggar Mahardhika committed
1716
import re
1717 1718 1719 1720 1721 1722 1723 1724 1725
@api_view(('POST',))
def createjalan(request):
    polyline = request.POST.get('polyline')
    name_jalan = request.POST.get('name_jalan')
    panjang_jalan = request.POST.get('panjang_jalan')
    lebar_jalan = request.POST.get('lebar_jalan')
    tipe_jalan = request.POST.get('tipe_jalan')
    img_jalan = request.FILES.get('gambar')
    
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1726 1727 1728 1729
    panjang_jalan = re.sub('[^0-9.]+', '', str(panjang_jalan))
    if lebar_jalan == '':
        lebar_jalan = 0
    print(panjang_jalan)
1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770
    coord = json.loads(str(polyline))
    print(coord)
    
    try:
        if coord['features'][0]['geometry']['type'] == 'LineString':
            for co in coord['features']:
                ll = str(co["geometry"]['coordinates'])
                ll += ll
            ll = ll.replace(", "," ")
            ll = ll.replace("]][[","),(")
            ll = ll.replace("] [",", ")
            ll = ll.replace("]]",")")
            ll = ll.replace("[[","(")

            coordinat = f'MULTILINESTRING({ll})'
    except:
        if coord['geometry']['type'] == 'LineString':
            
            ll = str(coord["geometry"]['coordinates'])
                
            ll = ll.replace(", "," ")
            ll = ll.replace("]][[","),(")
            ll = ll.replace("] [",", ")
            ll = ll.replace("]]",")")
            ll = ll.replace("[[","(")

            coordinat = f'MULTILINESTRING({ll})'
    fss_p = FileSystemStorage(location='static/image/jalan/')
    try:
        format = (img_jalan.name).split(".")
        num = random.randrange(1, 10000000000000)
        ngambar = f"{name_jalan}_{num}.{format[-1:][0]}"
        ngambar = ngambar.replace(" ","-")
        filename_p = fss_p.save(ngambar, img_jalan)
        url_p = fss_p.url(filename_p)
    except:
        ngambar = 'None'
    
    try:
                
        with conn.cursor() as jalan:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1771
            jalan.execute("""INSERT INTO geo_jalan(geom, namrjl, panjang_jalan, lebar_jalan, remark, gambar) VALUES (ST_GeomFromEWKT('SRID=4326;%s'), '%s', %s, %s,'%s','%s')"""% (coordinat, name_jalan, panjang_jalan, lebar_jalan, tipe_jalan, ngambar))
1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784
        conn.commit()
        
        data = 'SUCCESS'
        info = 'data telah diperbaharui'
        status = 0
    except:
        data = 'Opss..!!'
        info = 'Hubungi Developer'
        status = 1
    
    respon={'data':data, 'info': info, 'status':status}
    return Response(respon)

Manggar Mahardhika's avatar
Manggar Mahardhika committed
1785 1786 1787 1788
@api_view(('GET',))
def changetipe(request):
    tipe_point = request.GET.get('tipe')
    
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1789 1790 1791 1792
    if tipe_point == 'bangunan':
            tipepoint = [['Rumah'],['Ruko'],['Pabrik'],['Pasar/Swalayan']]
    
    if tipe_point == 'kantor_administrasi':
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1793 1794 1795 1796
        with conn.cursor() as point:
            point.execute("""SELECT DISTINCT remark FROM geo_kantor_administrasi""")
            tipepoint = point.fetchall()
        
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1797
    if tipe_point == 'layanan_kesehatan':
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1798 1799 1800 1801 1802 1803 1804 1805 1806
        with conn.cursor() as point:
            point.execute("""SELECT DISTINCT remark FROM geo_layanan_kesehatan""")
            tipepoint = point.fetchall()

    if tipe_point == 'puskesmas':
        with conn.cursor() as point:
            point.execute("""SELECT DISTINCT remark FROM geo_puskesmas""")
            tipepoint = point.fetchall()
        
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1807
    if tipe_point == 'rumah_sakit':
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1808 1809 1810 1811
        with conn.cursor() as point:
            point.execute("""SELECT DISTINCT remark FROM geo_rumah_sakit""")
            tipepoint = point.fetchall()
        
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1812
    if tipe_point == 'sarana_ibadah':
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1813 1814 1815 1816
        with conn.cursor() as point:
            point.execute("""SELECT DISTINCT remark FROM geo_sarana_ibadah""")
            tipepoint = point.fetchall()
        
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1817
    if tipe_point == 'sarana_pendidikan':
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1818 1819 1820 1821
        with conn.cursor() as point:
            point.execute("""SELECT DISTINCT remark FROM geo_sarana_pendidikan""")
            tipepoint = point.fetchall()
            
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1822
    if tipe_point == 'cagar_budaya':
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836
        with conn.cursor() as point:
            point.execute("""SELECT DISTINCT remark FROM geo_cagar_budaya""")
            tipepoint = point.fetchall()

    if tipe_point == 'spbu':
        with conn.cursor() as point:
            point.execute("""SELECT DISTINCT remark FROM geo_spbu""")
            tipepoint = point.fetchall()
            
    if tipe_point == 'stasiun':
        with conn.cursor() as point:
            point.execute("""SELECT DISTINCT remark FROM geo_stasiun""")
            tipepoint = point.fetchall()
            
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1837
    if tipe_point == 'terminal_bus':
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1838 1839 1840 1841
        with conn.cursor() as point:
            point.execute("""SELECT DISTINCT remark FROM geo_terminal_bus""")
            tipepoint = point.fetchall()
            
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1842
    if tipe_point == 'gardu_listrik':
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1843 1844 1845 1846 1847 1848
        with conn.cursor() as point:
            point.execute("""SELECT DISTINCT remark FROM geo_gardu_listrik""")
            tipepoint = point.fetchall()
    print(tipepoint)
    respon = {'result':tipepoint}
    return Response(respon)
1849

Manggar Mahardhika's avatar
Manggar Mahardhika committed
1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
@api_view(('GET',))
def changejenis(request):
    tipe_point = request.GET.get('tipe')
    jenis_point = request.GET.get('jenis')
    if tipe_point == 'bangunan':
        tipepoint1 = [['0','-']]
    else:
        with conn.cursor() as point:
            point.execute("""SELECT id, namobj FROM geo_%s where remark = '%s'"""% (tipe_point, jenis_point))
            tipepoint1 = point.fetchall()
    respon = {'result':tipepoint1}
    return Response(respon)

1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896
@api_view(('POST',))
def createpoint(request):
    gambar = request.FILES.get('gambar')
    co_point = request.POST.get('point')
    name_create_point = request.POST.get('name_create_point')
    tipe_point = request.POST.get('tipe_point')
    info_create_point = request.POST.get('info_create_point')
    alamat_create_point = request.POST.get('alamat_create_point')
    luas_bangunan_point = request.POST.get('luas_bangunan_point')
    luas_tanah_point = request.POST.get('luas_tanah_point')
    tinggi_bangunan_point = request.POST.get('tinggi_bangunan_point')
    lantai_point = request.POST.get('lantai_point')
    pemilik_point = request.POST.get('pemilik_point')
    
    
    coord = json.loads(str(co_point))
    
    coordinat = coord['geometry']['coordinates']
    
    fss_p = FileSystemStorage(location='static/img/image/')
    try:
        format = (gambar.name).split(".")
        num = random.randrange(1, 10000000000000)
        ngambar = f"{name_create_point}_{num}.{format[-1:][0]}"
        ngambar = ngambar.replace(" ","-")
        filename_p = fss_p.save(ngambar, gambar)
        url_p = fss_p.url(filename_p)
    except:
        ngambar = 'None'
    
    # update geo_rumah_sakit set geom = st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), namobj = '%s', alamat = '%s', remark = '%s', luas_bangunan = '%s', luas_tanah = '%s', tinggi_bangunan = '%s', perangkat = '%s', gambar = '%s' where id = %s
    try:
        if tipe_point == 'administrasi':
            with conn.cursor() as point:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1897
                point.execute("""INSERT INTO geo_kantor_administrasi(geom, namobj, remark, luas_tanah, alamat, perangkat, type_id, gambar) VALUES (st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), '%s','%s', %s, '%s', '%s', 5,'%s')"""% (coordinat, name_create_point, info_create_point, luas_tanah_point, alamat_create_point, pemilik_point, ngambar))
1898 1899 1900 1901
            conn.commit()
            
        if tipe_point == 'layanankesehatan':
            with conn.cursor() as point:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1902
                point.execute("""INSERT INTO geo_layanan_kesehatan(geom, namobj, remark, luas_tanah, alamat, perangkat, type_id, gambar) VALUES (st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), '%s','%s', %s, '%s', '%s', 6,'%s')"""% (coordinat, name_create_point, info_create_point, luas_tanah_point, alamat_create_point, pemilik_point, ngambar))
1903 1904 1905 1906
            conn.commit()

        if tipe_point == 'puskesmas':
            with conn.cursor() as point:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1907
                point.execute("""INSERT INTO geo_puskesmas(geom, namobj, remark, luas_tanah, alamat, perangkat, type_id, gambar) VALUES (st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), '%s','%s', %s, '%s', '%s', 7,'%s')"""% (coordinat, name_create_point, info_create_point, luas_tanah_point, alamat_create_point, pemilik_point, ngambar))
1908 1909 1910 1911
            conn.commit()
            
        if tipe_point == 'rumahsakit':
            with conn.cursor() as point:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1912
                point.execute("""INSERT INTO geo_rumah_sakit(geom, namobj, remark, luas_tanah, alamat, perangkat, type_id, gambar) VALUES (st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), '%s','%s', %s, '%s', '%s', 8,'%s')"""% (coordinat, name_create_point, info_create_point, luas_tanah_point, alamat_create_point, pemilik_point, ngambar))
1913 1914 1915 1916
            conn.commit()
            
        if tipe_point == 'saranaibadah':
            with conn.cursor() as point:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1917
                point.execute("""INSERT INTO geo_sarana_ibadah(geom, namobj, remark, luas_tanah, alamat, perangkat, type_id, gambar) VALUES (st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), '%s','%s', %s, '%s', '%s', 9,'%s')"""% (coordinat, name_create_point, info_create_point, luas_tanah_point, alamat_create_point, pemilik_point, ngambar))
1918 1919 1920 1921
            conn.commit()
            
        if tipe_point == 'saranapendidikan':
            with conn.cursor() as point:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1922
                point.execute("""INSERT INTO geo_sarana_pendidikan(geom, namobj, remark, luas_tanah, alamat, perangkat, type_id, gambar) VALUES (st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), '%s','%s', %s, '%s', '%s', 10,'%s')"""% (coordinat, name_create_point, info_create_point, luas_tanah_point, alamat_create_point, pemilik_point, ngambar))
1923 1924 1925 1926
            conn.commit()

        if tipe_point == 'cagarbudaya':
            with conn.cursor() as point:
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1927
                point.execute("""INSERT INTO geo_cagar_budaya(geom, namobj, remark, luas_tanah, alamat, perangkat, type_id, gambar) VALUES (st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), '%s','%s', %s, '%s', '%s', 3,'%s')"""% (coordinat, name_create_point, info_create_point, luas_tanah_point, alamat_create_point, pemilik_point, ngambar))
1928 1929
            conn.commit()
        
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948
        if tipe_point == 'spbu':
            with conn.cursor() as point:
                point.execute("""INSERT INTO geo_spbu(geom, namobj, remark, luas_tanah, alamat, perangkat, type_id, gambar) VALUES (st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), '%s','%s', %s, '%s', '%s', 3,'%s')"""% (coordinat, name_create_point, info_create_point, luas_tanah_point, alamat_create_point, pemilik_point, ngambar))
            conn.commit()
            
        if tipe_point == 'stasiun':
            with conn.cursor() as point:
                point.execute("""INSERT INTO geo_stasiun(geom, namobj, remark, luas_tanah, alamat, perangkat, type_id, gambar) VALUES (st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), '%s','%s', %s, '%s', '%s', 3,'%s')"""% (coordinat, name_create_point, info_create_point, luas_tanah_point, alamat_create_point, pemilik_point, ngambar))
            conn.commit()
            
        if tipe_point == 'terminalbus':
            with conn.cursor() as point:
                point.execute("""INSERT INTO geo_terminal_bus(geom, namobj, remark, luas_tanah, alamat, perangkat, type_id, gambar) VALUES (st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), '%s','%s', %s, '%s', '%s', 3,'%s')"""% (coordinat, name_create_point, info_create_point, luas_tanah_point, alamat_create_point, pemilik_point, ngambar))
            conn.commit()
            
        if tipe_point == 'gardulistrik':
            with conn.cursor() as point:
                point.execute("""INSERT INTO geo_gardu_listrik(geom, namobj, remark, luas_tanah, alamat, perangkat, type_id, gambar) VALUES (st_geomfromgeojson('{"type":"Point", "coordinates":%s, "crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'), '%s','%s', %s, '%s', '%s', 3,'%s')"""% (coordinat, name_create_point, info_create_point, luas_tanah_point, alamat_create_point, pemilik_point, ngambar))
            conn.commit()
1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959
        
        data = 'SUCCESS'
        info = 'data telah diperbaharui'
        status = 0
    except:
        data = 'Opss..!!'
        info = 'Hubungi Developer'
        status = 1
    
    respon={'data':data, 'info': info, 'status':status}
    return Response(respon)