예제 #1
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_strip_srid(self):
     """
     strip SRID
     """
     geom1 = Geometry("010100000000000000000000000000000000000000")
     geom2 = Geometry("0101000020E610000000000000000000000000000000000000")
     self.assertIsNone(geom1.srid)
     self.assertEquals(geom2.srid, 4326)
     geom2.srid = None
     self.assertIsNone(geom2.srid)
     self.assertEquals(geom1.wkb, geom2.wkb)
     geom2.srid = None
     self.assertIsNone(geom2.srid)
     self.assertEquals(geom1.wkb, geom2.wkb)
예제 #2
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_read_wkb_point(self):
     """
     read WKB Point
     """
     wkb = "010100000000000000000000000000000000000000"
     geom = Geometry(wkb)
     self.assertEquals(geom.type, "Point")
     self.assertIsNone(geom.srid)
     self.assertEquals(geom.dimz, False)
     self.assertEquals(geom.dimm, False)
     postgis_type = "geometry(Point)"
     self.assertEquals(geom.postgis_type, postgis_type)
     self.assertEquals(geom.__repr__(), "<Point: 'geometry(Point)'>")
     geom.srid = geom.srid  # clear cached WKB
     self.assertEquals(geom.__str__().lower(), wkb.lower())
예제 #3
0
  def _get_predicates(self, quals):
    query = None
    bounds = None
    for qual in quals:
      if qual.field_name == 'query' and qual.operator == '=':
        query = qual.value

      if qual.field_name == 'geom' and qual.operator in ['&&', '@']: # note A ~ B is transformed into B @ A
        shape = Geometry(qual.value).shapely
        bounds = shape.bounds
      elif qual.value == 'geom' and qual.operator == '&&':
        shape = Geometry(qual.field_name).shapely
        bounds = shape.bounds

    return query, bounds
예제 #4
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_read_ewkb_point_srid(self):
     """
     read EWKB Point,4326
     """
     wkb = "0101000020E610000000000000000000000000000000000000"
     geom = Geometry(wkb)
     self.assertEquals(geom.type, "Point")
     self.assertEquals(geom.srid, 4326)
     self.assertEquals(geom.dimz, False)
     self.assertEquals(geom.dimm, False)
     postgis_type = "geometry(Point,4326)"
     self.assertEquals(geom.postgis_type, postgis_type)
     self.assertEquals(geom.__repr__(), "<Point: 'geometry(Point,4326)'>")
     geom.srid = geom.srid  # clear cached WKB
     self.assertEquals(geom.__str__().lower(), wkb.lower())
예제 #5
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_shape(self):
     """
     access using __geo_interface__ and shape
     """
     point = Point.from_geojson(geojson_pt)
     geom = Geometry.shape(point)
     self.assertEquals(point.__geo_interface__, geom.__geo_interface__)
예제 #6
0
def containsPoint(request):  #위험 지역 우회
    global gu_coordinate
    pointlist = []
    line = ""
    line_point = []
    count = 0
    gu_bound = Female2.objects.filter(female2_crime_type="구경계", gu="양천구").get()
    gis = Geometry(gu_bound.female2_crime_loc.hex()[8:])
    gi = shape(gis)
    if request.method == "POST":
        pistes = request.POST.get('draw')
        pist = pistes.split(",")
        for p in pist:
            if (pist.index(p) % 2 == 0):
                x = p
                y = pist[pist.index(p) + 1]
                point = Point(float(y), float(x))
                pointlist.append(point)

        linear = LineString(pointlist).buffer(0.003)

        for multi in global_contain_coordinate:
            if linear.contains(multi):
                linear = linear.difference(multi.buffer(0.0))

        if linear.intersection(gi).geom_type == 'Polygon':
            line += "_" + str(linear.centroid.x) + "," + str(linear.centroid.y)
        else:
            for l in list(linear.intersection(gi)):
                line += "_" + str(l.centroid.x) + "," + str(l.centroid.y)

    return HttpResponse(json.dumps({'p': line[1:]}),
                        content_type="application/json")
예제 #7
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_shapely_load(self):
     """
     convert from Shapely
     """
     sgeom = geometry.Point(99, -99)
     point = Geometry.from_shapely(sgeom)
     self.assertEquals(sgeom.wkb_hex.upper(), point.wkb.upper())
예제 #8
0
def donglevel(request):
    map = folium.Map(location=[37.5518838, 126.9858763], zoom_start=12)
    dongm = DongLevel.objects.values('dong_level_tot', 'dong_nm')
    dong_df = pd.DataFrame(dongm)
    dongloc = DongLevel.objects.all()
    loc_list = []
    for i in dongloc:
        gis = Geometry(i.dong_loc.hex()[8:])
        crime_location = {
            "type": "Feature",
            "properties": {
                "dong_nm": i.dong_nm
            },
            "geometry": gis.geojson
        }
        loc_list.append(crime_location)
    pistes = {"type": "FeatureCollection", "features": loc_list}

    folium.Choropleth(geo_data=pistes,
                      data=dong_df,
                      columns=('dong_nm', 'dong_level_tot'),
                      fill_color='BuPu',
                      key_on='feature.properties.dong_nm').add_to(map)

    maps = map._repr_html_()
    return render(request, 'home.html', {'map': maps})
예제 #9
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_read_wkb_polygon(self):
     """
     read WKB Polygon
     """
     wkb = wkb_pg
     geom = Geometry(wkb)
     self.assertEquals(geom.type, "Polygon")
     self.assertEquals(geom.srid, None)
     self.assertEquals(geom.dimz, False)
     self.assertEquals(geom.dimm, False)
     postgis_type = "geometry(Polygon)"
     self.assertEquals(geom.exterior.type, "LineString")
     self.assertEquals(geom.postgis_type, postgis_type)
     self.assertEquals(geom.__repr__(), "<Polygon: 'geometry(Polygon)'>")
     geom.srid = geom.srid  # clear cached WKB
     self.assertEquals(geom.__str__().lower(), wkb.lower())
예제 #10
0
def pathFinder(request): #위험지역 받는 함수
    global startX,startY,endX,endY,startGu,endGu
    gu_list=['종로구','중구','용산구','성동구','광진구',
    '동대문구','중랑구','성북구','강북구','도봉구',
    '노원구','은평구','서대문구','마포구','양천구',
    '강서구','구로구','금천구','영등포구','동작구',
    '관악구','서초구','강남구','송파구','강동구',]
    loc_list=[]
    if request.method=="POST":
        startPoint=request.POST.get('start')
        endPoint=request.POST.get('end')
        startX=request.POST.get('startX')
        startY=request.POST.get('startY')
        endX=request.POST.get('endX')
        endY=request.POST.get('endY')
        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:])
            contain_coordinate=shape(gis.geojson)
            crime_location={"type":"Feature","geometry":gis.geojson}
            loc_list.append(crime_location)
    pistes = {"type":"FeatureCollection","features":loc_list}
    return HttpResponse(json.dumps({'result':pistes}),content_type="application/json")
예제 #11
0
파일: geometry.py 프로젝트: bosth/plpygis
 def test_read_wkb_point_big_endian(self):
     """
     read WKB Point
     """
     geom = Geometry("000000000140000000000000004010000000000000")
     self.assertIsInstance(geom, Point)
     self.assertEqual((2, 4, None), (geom.x, geom.y, geom.z))
예제 #12
0
def showFemale(request):
    global g
    global getGu
    crime_type=""
    loc_list=[]
    if request.method=="POST":
        filter_value=request.POST['female_filter']
        crime_type="전체_"+filter_value
    female_total=Female2.objects.filter(gu=getGu,female2_crime_type=crime_type).all()

    linear = cmp.LinearColormap(
    [ 'green','blue','red'],
    vmin=10, vmax=300)

    map = folium.Map(location=[37.55582994870823, 126.9726320033982],zoom_start=15)
    for loc in female_total:
        gis= Geometry(loc.female2_crime_loc.hex()[8:])
        contain_coordinate=shape(gis.geojson)
        crime_location={"type":"Feature","properties":{'area':math.ceil(round(contain_coordinate.length,5)*100000)},"geometry":gis.geojson}
        folium.GeoJson(crime_location,style_function=lambda feature: {
            'fillColor': linear(feature['properties']['area']),
            'color': linear(feature['properties']['area']),     
            'weight': 1  
        }).add_to(map)
        linear.add_to(map)
    
    
    maps=map._repr_html_()
    return render(request, 'home.html',{'map':maps})
예제 #13
0
def converterFeature(geometry):
	g = Geometry(geometry)
	coord = g.geojson['coordinates'][0][0]
	saida = []
	for c in coord:
		c.reverse()
		saida.append(c)
	return saida
예제 #14
0
def converterGeometryPolygon(geometry):
	g = Geometry(geometry)
	coord = g.geojson['coordinates']
	saida = []
	for c in coord[0]:
		c.reverse()
		saida.append(c)
	return saida
예제 #15
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_read_wkb_linestring(self):
     """
     read WKB LineString
     """
     wkb = wkb_ln
     geom = Geometry(wkb)
     self.assertEquals(geom.type, "LineString")
     self.assertEquals(geom.srid, None)
     self.assertEquals(geom.dimz, False)
     self.assertEquals(geom.dimm, False)
     postgis_type = "geometry(LineString)"
     geom.vertices
     self.assertEquals(geom.postgis_type, postgis_type)
     self.assertEquals(geom.__repr__(),
                       "<LineString: 'geometry(LineString)'>")
     geom.srid = geom.srid  # clear cached WKB
     self.assertEquals(geom.__str__().lower(), wkb.lower())
예제 #16
0
def aStar(request):
    global startGu, endGu
    center = hexgrid.Point((float(startX) + float(endX)) / 2,
                           (float(startY) + float(endY)) / 2)
    rate = 110.574 / (111.320 * math.cos(37.55582994870823 * math.pi / 180))
    grid = hexgrid.Grid(hexgrid.OrientationFlat, center,
                        Point(rate * 0.00015, 0.00015), morton.Morton(2, 32))
    sPoint = grid.hex_at(Point(float(startX), float(startY)))
    ePoint = grid.hex_at(Point(float(endX), float(endY)))
    map_size = max(abs(sPoint.q), abs(sPoint.r))
    road1 = Roadtohexgrid.objects.filter(is_danger=1, hexgrid_gu=startGu).all()
    road2 = Roadtohexgrid.objects.filter(is_danger=1, hexgrid_gu=endGu).all()
    total_road = road1.union(road2, all=False)
    wall1 = Roadtohexgrid.objects.filter(is_danger=0, hexgrid_gu=startGu).all()
    wall2 = Roadtohexgrid.objects.filter(is_danger=0, hexgrid_gu=endGu).all()
    total_wall = wall1.union(wall2, all=False)
    wh = GridWithWeights(layout_flat, Point(rate * 0.00015, 0.00015), center,
                         map_size + 5)
    for r in total_road:
        gis = Geometry(r.hexgrid_loc.hex()[8:])
        h = grid.hex_at(shape(gis.geojson))
        wh.weights[(h.q, h.r)] = 1

    for w in total_wall:
        gis = Geometry(w.hexgrid_loc.hex()[8:])
        h = grid.hex_at(shape(gis.geojson))
        wh.weights[(h.q, h.r)] = 200

    start, goal = (sPoint.q, sPoint.r), (ePoint.q, ePoint.r)
    came_from, cost_so_far = a_star_search(wh, start, goal)
    pointList = reconstruct_path(came_from, start=start, goal=goal)
    plist = []
    for p in pointList:
        point = wh.hex_to_pixel(hexgrid.Hex(p[0], p[1]))
        plist.append([point.x, point.y])
    crime_location = {
        "type": "Feature",
        "geometry": {
            "type": "LineString",
            "coordinates": plist
        }
    }
    pistes = {"type": "FeatureCollection", "features": [crime_location]}

    return HttpResponse(json.dumps({'pistes': pistes}),
                        content_type="application/json")
예제 #17
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_read_wkb_multilinestring(self):
     """
     read WKB MultiLineString
     """
     wkb = wkb_mln
     geom = Geometry(wkb)
     self.assertEquals(geom.type, "MultiLineString")
     self.assertEquals(geom.srid, None)
     self.assertEquals(geom.dimz, False)
     self.assertEquals(geom.dimm, True)
     postgis_type = "geometry(MultiLineStringM)"
     self.assertEquals(geom.postgis_type, postgis_type)
     self.assertEquals(geom.__repr__(),
                       "<MultiLineString: 'geometry(MultiLineStringM)'>")
     geom.srid = geom.srid  # clear cached WKB
     self.assertEquals(geom.__str__().lower(), wkb.lower())
     for g in geom.geometries:
         self.assertEquals(g.type, "LineString")
예제 #18
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_read_wkb_multipolygon(self):
     """
     read WKB MultiPolygon
     """
     wkb = wkb_mpg
     geom = Geometry(wkb)
     self.assertEquals(geom.type, "MultiPolygon")
     self.assertEquals(geom.srid, None)
     self.assertEquals(geom.dimz, False)
     self.assertEquals(geom.dimm, False)
     postgis_type = "geometry(MultiPolygon)"
     self.assertEquals(geom.postgis_type, postgis_type)
     self.assertEquals(geom.__repr__(),
                       "<MultiPolygon: 'geometry(MultiPolygon)'>")
     geom.srid = geom.srid  # clear cached WKB
     self.assertEquals(geom.__str__().lower(), wkb.lower())
     for g in geom.geometries:
         self.assertEquals(g.type, "Polygon")
예제 #19
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_translate_geojson_pt(self):
     """
     load and dump GeoJSON point
     """
     geom = Geometry.from_geojson(geojson_pt)
     self.assertEquals(geom.srid, 4326)
     self.assertEquals(Point, type(geom))
     geojson = geom.geojson
     self.assertEquals(geojson, geojson_pt)
예제 #20
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_translate_geojson_mln(self):
     """
     load and dump GeoJSON multiline
     """
     geom = Geometry.from_geojson(geojson_mln)
     self.assertEquals(geom.srid, 4326)
     self.assertEquals(MultiLineString, type(geom))
     geojson = geom.geojson
     self.assertEquals(geojson, geojson_mln)
예제 #21
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_translate_geojson_gc(self):
     """
     load and dump GeoJSON GeometryCollection
     """
     geom = Geometry.from_geojson(geojson_gc)
     self.assertEquals(geom.srid, 4326)
     self.assertEquals(GeometryCollection, type(geom))
     geojson = geom.geojson
     self.assertEquals(geojson, geojson_gc)
예제 #22
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_translate_geojson_mpg(self):
     """
     load and dump GeoJSON multipolygon
     """
     geom = Geometry.from_geojson(geojson_mpg)
     self.assertEquals(geom.srid, 4326)
     self.assertEquals(MultiPolygon, type(geom))
     geojson = geom.geojson
     self.assertEquals(geojson, geojson_mpg)
예제 #23
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_bounds_geomcollection(self):
     """
     check bounds of GeometryCollection
     """
     geom = Geometry.from_geojson(geojson_gc)
     bounds = geom.bounds
     self.assertEquals(bounds[0], 10)
     self.assertEquals(bounds[1], 0)
     self.assertEquals(bounds[2], 12)
     self.assertEquals(bounds[3], 1)
예제 #24
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_bounds_multipolygon(self):
     """
     check bounds of MultiPolygon
     """
     geom = Geometry.from_geojson(geojson_mpg)
     bounds = geom.bounds
     self.assertEquals(bounds[0], 1)
     self.assertEquals(bounds[1], 0)
     self.assertEquals(bounds[2], 111)
     self.assertEquals(bounds[3], 1)
예제 #25
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_bounds_multilinestring(self):
     """
     check bounds of MultiLineString
     """
     geom = Geometry.from_geojson(geojson_mln)
     bounds = geom.bounds
     self.assertEquals(bounds[0], 0)
     self.assertEquals(bounds[1], 0)
     self.assertEquals(bounds[2], 3)
     self.assertEquals(bounds[3], 3)
예제 #26
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_bounds_polygon(self):
     """
     check bounds of Polygon
     """
     geom = Geometry.from_geojson(geojson_pg)
     bounds = geom.bounds
     self.assertEquals(bounds[0], 100)
     self.assertEquals(bounds[1], 0)
     self.assertEquals(bounds[2], 101)
     self.assertEquals(bounds[3], 1)
예제 #27
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_bounds_linestring(self):
     """
     check bounds of LineString
     """
     geom = Geometry.from_geojson(geojson_ln)
     bounds = geom.bounds
     self.assertEquals(bounds[0], 102)
     self.assertEquals(bounds[1], 59)
     self.assertEquals(bounds[2], 107)
     self.assertEquals(bounds[3], 60)
예제 #28
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_read_wkb_geometrycollection(self):
     """
     read WKB GeometryCollection
     """
     wkb = wkb_gc
     geom = Geometry(wkb)
     self.assertEquals(geom.type, "GeometryCollection")
     self.assertEquals(geom.srid, None)
     self.assertEquals(geom.dimz, False)
     self.assertEquals(geom.dimm, False)
     postgis_type = "geometry(GeometryCollection)"
     self.assertEquals(geom.postgis_type, postgis_type)
     self.assertEquals(
         geom.__repr__(),
         "<GeometryCollection: 'geometry(GeometryCollection)'>")
     geom.srid = geom.srid  # clear cached WKB
     self.assertEquals(geom.__str__().lower(), wkb.lower())
     self.assertEquals(geom.geometries[0].type, "Point")
     self.assertEquals(geom.geometries[1].type, "LineString")
예제 #29
0
파일: geometry.py 프로젝트: bosth/plpygis
 def test_bounds_multipoint(self):
     """
     check bounds of MultiPoint
     """
     geom = Geometry.from_geojson(geojson_mpt)
     bounds = geom.bounds
     self.assertEqual(bounds[0], 0)
     self.assertEqual(bounds[1], 0)
     self.assertEqual(bounds[2], 1)
     self.assertEqual(bounds[3], 1)
예제 #30
0
파일: geometry.py 프로젝트: lovasoa/plpygis
 def test_bounds_point(self):
     """
     check bounds of Point
     """
     geom = Geometry.from_geojson(geojson_pt)
     bounds = geom.bounds
     self.assertEquals(bounds[0], 0.0)
     self.assertEquals(bounds[1], 0.0)
     self.assertEquals(bounds[2], 0.0)
     self.assertEquals(bounds[3], 0.0)