Пример #1
0
def filter_safetyzone(request):  #안심장소보기
    global getGu
    safety_type = ""
    gu_type = ""
    mkurl = ""
    map = folium.Map(location=[37.55582994870823, 126.9726320033982],
                     zoom_start=12)

    if request.method == "POST":
        filter_value = request.POST['safetyZone_filter']
        safety_type = filter_value

    # 편의점을 선택한 경우 선택된 구를 출력
    if (safety_type == "편의점"):
        mkurl = "safety_map/static/img/mk_cvs.png"  #편의점 마커 이미지
        safetyzone_ob_all = SafetyZone.objects.filter(
            gu=getGu)  # 구 입력 방식 정해지면 '종로구'자리에 gu_type 넣으면 된다.

    # 경찰서, 지구대, 파출소를 선택한 경우 서울 전체
    else:
        if (safety_type == "경찰서"):
            mkurl = "safety_map/static/img/mk_police_station.png"  # 경찰서 마커 이미지
        elif (safety_type == "지구대"):
            mkurl = "safety_map/static/img/mk_police_unit.png"  # 지구대 마커 이미지
        elif (safety_type == "파출소"):
            mkurl = "safety_map/static/img/mk_police_box.png"  # 파출소 마커 이미지
        safetyzone_ob_all = SafetyZone.objects.filter(
            safety_type=safety_type).all()

    # 마커 지도에 추가
    for loc in safetyzone_ob_all:
        icon = folium.features.CustomIcon(icon_image=mkurl, icon_size=(50, 50))
        gis = Geometry(loc.safety_loc.hex()[8:])
        to_geojson = convert.wkt_to_geojson(str(gis.shapely))
        to_coordinate = json.loads(to_geojson)
        marker = folium.map.Marker(
            [to_coordinate['coordinates'][0], to_coordinate['coordinates'][1]],
            icon=icon)
        marker.add_to(map)

    maps = map._repr_html_()
    return render(request, 'home.html', {'map': maps})
Пример #2
0
def showKid(request):  #아동필터
    global g
    global getGu
    accident_type = ""
    loc_list = []

    if request.method == 'POST':
        filter_value = request.POST["kid_filter"]
        accident_type = filter_value

    # 어린이 보행사고를 클릭한 경우
    if filter_value == "스쿨존사고":
        accident_type = filter_value + "다발지역"
    elif filter_value == "어린이보행사고":
        accident_type = filter_value
    else:
        accident_type = filter_value

    kid_accident = Kid.objects.filter(gu=getGu,
                                      kid_accident_type=accident_type).all()

    #colormap_dept = cmp.StepColormap(colors=['#00ae53', '#86dc76', '#daf8aa','#ffe6a4', '#ff9a61', '#ee0028'],
    #                                vmin=10, vmax=310)

    for i in kid_accident:
        gis = Geometry(i.kid_accident_loc.hex()[8:])
        to_geojson = convert.wkt_to_geojson(str(gis.shapely))
        to_coordinate = json.loads(to_geojson)
        contain_coordinate = shape(to_coordinate)
        crime_location = {"type": "Feature", "geometry": to_coordinate}
        loc_list.append(crime_location)
    pistes = {"type": "FeatureCollection", "features": loc_list}

    map = folium.Map(location=[37.55582994870823, 126.9726320033982],
                     zoom_start=15)

    folium.GeoJson(pistes).add_to(map)

    maps = map._repr_html_()
    return render(request, 'home.html', {'map': maps, 'pistes': pistes})
Пример #3
0
import os
import json
from glob import glob

import geodaisy.converters as convert
import visvalingamwyatt as vw

for json_file in glob('*.json'):
    print(json_file)

    with open(json_file, 'r') as fh_in:
        j = json.load(fh_in)
        shape = j['View'][0]['Result'][0]['Location']['Shape']['Value']

        try:
            shape = json.loads(convert.wkt_to_geojson(shape))
            shape = vw.simplify_geometry(shape, ratio=0.2)
            j['View'][0]['Result'][0]['Location']['Shape'][
                'Value'] = convert.geojson_to_wkt(shape)
        except (ValueError, TypeError):
            print('>>>>')

        with open('{}-simplified{}'.format(*os.path.splitext(json_file)),
                  'w') as fh_out:
            json.dump(j, fh_out)
Пример #4
0
def pathFinder(request):  #위험지역 받는 함수
    global global_contain_coordinate
    global gu_coordinate
    gu_list = [
        '종로구',
        '중구',
        '용산구',
        '성동구',
        '광진구',
        '동대문구',
        '중랑구',
        '성북구',
        '강북구',
        '도봉구',
        '노원구',
        '은평구',
        '서대문구',
        '마포구',
        '양천구',
        '강서구',
        '구로구',
        '금천구',
        '영등포구',
        '동작구',
        '관악구',
        '서초구',
        '강남구',
        '송파구',
        '강동구',
    ]
    loc_list = []
    if request.method == "POST":
        startPoint = request.POST.get('start')
        endPoint = request.POST.get('end')
        print(startPoint, endPoint)
        for find_gu in gu_list:
            if find_gu in startPoint:
                startGu = find_gu
            else:
                pass
            if find_gu in endPoint:
                endGu = find_gu
            else:
                pass
        female_start = Female2.objects.filter(female2_crime_type="전체_전체",
                                              gu=startGu).all()
        female_end = Female2.objects.filter(female2_crime_type="전체_전체",
                                            gu=endGu).all()
        female_total = female_start.union(female_end, all=False)
        for loc in female_total:
            gis = Geometry(loc.female2_crime_loc.hex()[8:])
            to_geojson = convert.wkt_to_geojson(str(gis.shapely))
            to_coordinate = json.loads(to_geojson)
            contain_coordinate = shape(to_coordinate)
            global_contain_coordinate.append(contain_coordinate)
            crime_location = {"type": "Feature", "geometry": to_coordinate}
            loc_list.append(crime_location)
    pistes = {"type": "FeatureCollection", "features": []}

    return HttpResponse(json.dumps({'pistes': pistes}),
                        content_type="application/json")
Пример #5
0
def test_geojson_from_wkt(shape):
    test_geojson = convert.wkt_to_geojson(shape)
    check = geojson.loads(test_geojson)

    assert check.is_valid