def _polyencode(self): import gpolyencode encoder = gpolyencode.GPolyEncoder() points = [] for point in self.path: tokens = point.split(',') points.append((float(tokens[1]),float(tokens[0]))) return encoder.encode(points)['points']
def get_greenline(): """ Query Greenline and return encoded polylines optimized for Google Maps. """ greenline = Line.objects.all() # encode linestrings encoder = gpolyencode.GPolyEncoder() for line in greenline: line.encoded = encoder.encode(line.geometry.coords) return greenline
def encode(limits): """ >>> import gpolyencode >>> encoder = gpolyencode.GPolyEncoder() >>> points = ((8.94328,52.29834), (8.93614,52.29767), (8.93301,52.29322), (8.93036,52.28938), (8.97475,52.27014),) >>> encoder.encode(points) {'points':'soe~Hovqu@dCrk@xZpR~VpOfwBmtG', 'levels':'PG@IP', 'zoomFactor':2, 'numLevels':18} """ encoder = gpolyencode.GPolyEncoder() points = tuple( [tuple([float(b) for b in a.split(',')]) for a in limits.split(' ')]) return encoder.encode(points)
def create_map_url(info): # TODO finish this try: encoder = gpolyencode.GPolyEncoder() for area in info.area_set.all(): if area.geom: # We do this to prevent tests from bombing out... image_url = None latlng = [] for poly in area.geom.simplify(0.001, preserve_topology=True): for x, y in poly.coords[0]: latlng.append((round(x, 4), round(y, 4))) enc = encoder.encode(latlng) enc = enc['points'] image_url = "http://maps.googleapis.com/maps/api/staticmap?size=610x340&" \ "maptype=roadmap&path=fillcolor:0xAA000033%7Ccolor:0xFFFFFF00%7Cenc:{0:s}&"\ "&scale=2&sensor=false".format(enc) except: logging.error("Error in create_map_url")
def processPolylines(): encoder = gpolyencode.GPolyEncoder() json_data = open('data.txt') datadir = os.path.join(os.getcwd(), 'data') gtfsdir = os.path.join(datadir, 'gtfs') geojsondir = os.path.join(datadir, 'geojson') polydir = os.path.join(datadir, 'polylines') data = json.load(json_data, object_hook=_decode_dict) # pprint(data) json_data.close() with open(gtfsdir + "/shapes.txt", 'wb') as shapesfile: shapeswriter = csv.writer(shapesfile) shapeswriter.writerow([ "shape_id", "shape_pt_sequence", "shape_dist_traveled", "shape_pt_lon", "shape_pt_lat" ]) for trip, stops in data.items(): print trip legpoints = [] jsonpoints = [] for i in range(20): filepath = os.path.join(polydir, trip + "_" + str(i) + ".json") if (os.path.exists(filepath)): gmaps = open(filepath) linedata = json.load(gmaps) print trip + "_" + str(i) if args.dir == 'goog': if linedata['status'] != "OK": continue print linedata['routes'][0]['overview_polyline'][ 'points'] points = decode(linedata['routes'][0] ['overview_polyline']['points']) # print points for point in points: dictpoint = {'x': point[0], 'y': point[1]} legpoints.append(dictpoint) gmaps.close() elif args.dir == 'osrm': if linedata['status'] != 0: continue print linedata['route_geometry'] points = decode(linedata['route_geometry']) # print points for point in points: dictpoint = { 'x': point[0] / 10, 'y': point[1] / 10 } legpoints.append(dictpoint) gmaps.close() # print legpoints # print ls.geojson if not legpoints: continue else: simplified = simplify(legpoints, .0002, True) # print "new:" + str(simplified) count = 0 for point in simplified: jsonpoints.append((point['x'], point['y'])) shppoint = [point['x'], point['y']] shppoint.insert(0, trip) shppoint.insert(1, count) shppoint.insert(2, "") shapeswriter.writerow(shppoint) count += 1 ls = LineString(jsonpoints) gc = GeometryCollection([ls]) gtfsfile = os.path.join(geojsondir, trip + '.geojson') with open(gtfsfile, 'wb') as tripgeo: geojson.dump(gc, tripgeo)
def setUp(self): self.E = gpolyencode.GPolyEncoder self.e = gpolyencode.GPolyEncoder()