Пример #1
0
    def simplify(self, xData, yData, eps):
        pts = []
        for item in np.arange(len(xData)):
            pts.append((xData[item], yData[item]))

        # print ('[x,y]: ')
        # print ('' + str(np.array(pts)))

        pts = simplify_points(pts, eps)

        # print ('[xS,yS]: ')
        # print ('' + str(np.array(pts)))

        xPts = []
        yPts = []
        for item in np.arange(len(pts)):
            xPts.append(pts[item][0])
            yPts.append(pts[item][1])

        # print ('[x]: ')
        # print ('' + str(np.array(xPts)))
        # print ('[y]: ')
        # print ('' + str(np.array(xPts)))

        xPts = np.array(xPts)
        yPts = np.array(yPts)
        return xPts, yPts
Пример #2
0
	def simplify(self, xData, yData, eps):
		pts = []
		for item in np.arange(len(xData)):
			pts.append((xData[item], yData[item]))

		# print ('[x,y]: ')
		# print ('' + str(np.array(pts)))

		pts = simplify_points(pts, eps)

		# print ('[xS,yS]: ')
		# print ('' + str(np.array(pts)))

		xPts = []
		yPts = []
		for item in np.arange(len(pts)):
			xPts.append(pts[item][0])
			yPts.append(pts[item][1])

		# print ('[x]: ')
		# print ('' + str(np.array(xPts)))
		# print ('[y]: ')
		# print ('' + str(np.array(xPts)))

		xPts = np.array(xPts)
		yPts = np.array(yPts)
		return xPts, yPts
Пример #3
0
def main(filename, output):
    data = json.load(open(filename, 'rb'))
    for polygon in data['features']:
        counter = 0
        coords = []
        for coordinates in polygon['geometry']['coordinates']:
            points = simplify_points(coordinates, .15)
            counter += len(points)
            coords.append(points)
        polygon['geometry']['coordinates'] = coords
        polygon['properties']['count'] = counter
    json.dump(data, open(output, 'wb'), indent=4)
Пример #4
0
def calcTotalAscent(trackpoints):
    asc = 0

    points = []

    for p in trackpoints:
        if p.dist and p.alt:
            points.append((p.dist, p.alt))

    points = dp.simplify_points(points, 2.5)

    for i in range(len(points) - 1):
        diff = points[i + 1][1] - points[i][1]
        if diff > 0:
            asc += diff

    return asc
Пример #5
0
def simplify_poly(poly):
    """ Simplify
    """
    new_poly = []
    for idx, ring in enumerate(poly):
        if len(ring) < 25:
            tolerance = 0.01
        elif len(ring) < 50:
            tolerance = 0.03
        else:
            tolerance = 0.12
        new_ring = dp.simplify_points(ring, tolerance)
        if len(new_ring) < 4:
            if idx == 0:
                return []

        else:
            new_poly.append(new_ring)

    return new_poly
Пример #6
0
  def tabletEvent(self, event):
    if event.type() != event.TabletMove: return
    event.accept()
    if event.pressure() > self.MINIMUM_PRESSURE:
      if self.stroke_start:
        self.stroke_items.append([])
        self.stroke_start = False
      point = self.draw_point(event)
      self.stroke_items[-1].append(point)
      self.stroke_points.append((event.x(), event.y()))
    elif event.pressure() == 0 and self.stroke_points:
      simplified = simplify_points(self.stroke_points, 5)
      for p1, p2 in zip(simplified[:-1], simplified[1:]):
        line = self.draw_line(p1, p2)
        self.stroke_items[-1].append(line)

      self.strokes.append(simplified)
      self.recognize()

      self.stroke_points = []
      self.stroke_start = True
Пример #7
0
def simplify(filename, basic=False):

    with open(filename) as fp:

        soup = BeautifulStoneSoup(fp)

        kml = simplekml.Kml()
        multipnt = kml.newmultigeometry(name="MultiPoint")

        # import pdb; pdb.set_trace()

        allcoords = sorted([coords.text.split() for coords in soup.findAll("coordinates")], key=lambda elem: len(elem), reverse=True)

        if basic and len(allcoords) > 1:
            allcoords = allcoords[:2]

        for coords_group in allcoords:
            coords = [map(float, line.split(",")) for line in coords_group]
            multipnt.newpolygon(name="",
                                outerboundaryis=simplify_points(coords, 0.01))

        return kml.kml()