def main():
    if len(sys.argv) != 3:
        return 0
    segments = int(sys.argv[2])
    pointlist = (sys.argv[1].split(';'))
    coordlist = []
    for point in pointlist:
        coords = point.split(',')
        coordlist.append(
            projections.from4326((float(coords[0]), float(coords[1])),
                                 "EPSG:3857"))
    if len(coordlist) < 3:
        sys.stdout.write("<!--Too few control points-->")
        return 0
    if segments == 0:  # optimal number of segments
        for i in range(0, len(coordlist) - 2):
            P1 = coordlist[i]
            P2 = coordlist[i + 1]
            P1P2 = (P2[0] - P1[0], P2[1] - P1[1])
            P1P2abs = math.sqrt(P1P2[0] * P1P2[0] + P1P2[1] * P1P2[1])
            segments += math.ceil(math.log(P1P2abs, 4))  # cat's magic formula
        segments = int(segments)
    tData = OsmData()
    wayid = tData.addway()
    step = 1.0 / segments
    for i in range(segments + 1):
        t = step * i
        node = projections.to4326(getpoint(coordlist, t), "EPSG:3857")
        nodeid = tData.addnode()
        tData.nodes[nodeid][LON] = node[0]
        tData.nodes[nodeid][LAT] = node[1]
        tData.ways[wayid][REF].append(nodeid)
    tData.addcomment("Done.")
    tData.write(sys.stdout)
    return 0
def main():
  if len(sys.argv) != 3:
    return 0
  segments = int(sys.argv[2])
  pointlist = (sys.argv[1].split(';'))
  coordlist = []
  for point in pointlist:
    coords = point.split(',')
    coordlist.append(projections.from4326((float(coords[0]), float(coords[1])), "EPSG:3857"))
  if len(coordlist) < 3:
    sys.stdout.write("<!--Too few control points-->")
    return 0
  if segments == 0: # optimal number of segments
    for i in range(0, len(coordlist) - 2):
      P1 = coordlist[i]
      P2 = coordlist[i+1]
      P1P2 = (P2[0]-P1[0], P2[1]-P1[1])
      P1P2abs = math.sqrt(P1P2[0]*P1P2[0] + P1P2[1]*P1P2[1])
      segments += math.ceil(math.log(P1P2abs, 4)) # cat's magic formula
    segments=int(segments)
  tData = OsmData()
  wayid = tData.addway()
  step = 1.0 / segments
  for i in range(segments + 1):
    t = step * i
    node = projections.to4326(getpoint(coordlist, t), "EPSG:3857")
    nodeid = tData.addnode()
    tData.nodes[nodeid][LON] = node[0]
    tData.nodes[nodeid][LAT] = node[1]
    tData.ways[wayid][REF].append(nodeid)
  tData.addcomment("Done.")
  tData.write(sys.stdout)
  return 0
def main():
  if len(sys.argv) != 3:
    return 0
  coords = (sys.argv[1].split(','))
  A = projections.from4326((float(coords[0]),float(coords[1])), "EPSG:3857")
  B = projections.from4326((float(coords[2]),float(coords[3])), "EPSG:3857")
  C = projections.from4326((float(coords[4]),float(coords[5])), "EPSG:3857")
  segments = int(sys.argv[2])
  AM = ((B[0] - A[0])/2, (B[1] - A[1])/2)
  BN = ((C[0] - B[0])/2, (C[1] - B[1])/2)
  M = (A[0] + AM[0], A[1] + AM[1])
  N = (B[0] + BN[0], B[1] + BN[1])
  MM = (AM[1], -AM[0])
  NN = (BN[1], -BN[0])
  O = intersect(MM, M, NN, N)
  OA = (O[0] - A[0], O[1] - A[1])
  r = math.sqrt(OA[0]*OA[0] + OA[1]*OA[1])
  arc = createarc(O, A, C, r, segments)
  
  tData = OsmData()
  wayid = tData.addway()
  for point in arc:
    p = projections.to4326(point, "EPSG:3857")
    newid = tData.addnode()
    tData.nodes[newid][LON] = p[0]
    tData.nodes[newid][LAT] = p[1]
    tData.nodes[newid][TAG] = {}
    tData.ways[wayid][REF].append(newid)
  
  tData.addcomment("Done.")
  tData.write(sys.stdout)
  #f = open("out.txt", "w")
  #tData.write(f)
  #f.close()
  return 0
def main():
    if len(sys.argv) != 6:
        return 0
    sides = int(sys.argv[5])
    if sides < 3:
        return 0
    coords = (sys.argv[1].split(','))
    lon = float(coords[0].replace(',', '.'))
    lat = float(coords[1].replace(',', '.'))
    radius1 = float(sys.argv[2].replace(',', '.'))/math.cos(math.radians(lat))
    radius2 = float(sys.argv[3].replace(',', '.'))/math.cos(math.radians(lat))
    rot_angle = math.radians(float(sys.argv[4].replace(',', '.')))
    if radius1 <= 0:
        return 0
    if radius2 <= 0:
        return 0
    startangle = 0
    coords_m = projections.from4326((lon,lat), "EPSG:3857")
    
    tData = OsmData()
    wayid = tData.addway()
    for i in range(sides):
        angle = startangle + 2*math.pi*i/sides
        x = coords_m[0] + radius1 * math.cos(angle) * math.cos(rot_angle) - radius2 * math.sin(angle) * math.sin(rot_angle)
        y = coords_m[1] + radius1 * math.cos(angle) * math.sin(rot_angle) + radius2 * math.sin(angle) * math.cos(rot_angle)
        node = projections.to4326((x, y), "EPSG:3857")
        nodeid = tData.addnode()
        tData.nodes[nodeid][LON] = node[0]
        tData.nodes[nodeid][LAT] = node[1]
        tData.ways[wayid][REF].append(nodeid)
    tData.ways[wayid][REF].append(tData.ways[wayid][REF][0])
    tData.addcomment("Done.")
    tData.write(sys.stdout)
    return 0
def main():
  if len(sys.argv) != 3:
    return 0
  segments = int(sys.argv[2])
  pointlist = (sys.argv[1].split(';'))
  coordlist = []
  for point in pointlist:
    coords = point.split(',')
    coordlist.append(projections.from4326((float(coords[0]), float(coords[1])), "EPSG:3857"))
  if len(coordlist) < 4:
    sys.stdout.write("<!--Too few control points-->")
    return 0
  if segments < 0:
    sys.stdout.write("<!--Segments must be greater than zero-->");
  
  tData = OsmData()
  wayid = tData.addway()
  step = 1.0 / segments
  for j in range (1, len(coordlist)-2):
    # for segments other than the first, skip the first point since it's the
    # last point of the previous segment - otherwise you'll get overlapping points
    # at the segment ends.
    if j > 1:
      segs = range(1,segments+1)
    else:
      segs = range(segments+1)
    for i in segs:
      t = step * i
      node = projections.to4326(spline_4p(t, coordlist[j-1], coordlist[j], coordlist[j+1], coordlist[j+2]), "EPSG:3857")
      nodeid = tData.addnode()
      tData.nodes[nodeid][LON] = node[0]
      tData.nodes[nodeid][LAT] = node[1]
      tData.ways[wayid][REF].append(nodeid)
  tData.addcomment("Done.")
  tData.write(sys.stdout)
  return 0
示例#6
0
def main():
    if len(sys.argv) != 4:
        return 0
    coords = (sys.argv[1].split(','))
    A = projections.from4326((float(coords[0]), float(coords[1])), "EPSG:3857")
    B = projections.from4326((float(coords[2]), float(coords[3])), "EPSG:3857")
    C = projections.from4326((float(coords[4]), float(coords[5])), "EPSG:3857")
    segments = int(sys.argv[2])
    params = int(sys.argv[3])
    AM = ((B[0] - A[0]) / 2, (B[1] - A[1]) / 2)
    BN = ((C[0] - B[0]) / 2, (C[1] - B[1]) / 2)
    M = (A[0] + AM[0], A[1] + AM[1])
    N = (B[0] + BN[0], B[1] + BN[1])
    MM = (AM[1], -AM[0])
    NN = (BN[1], -BN[0])
    O = intersect(MM, M, NN, N)  # circle center
    OA = (O[0] - A[0], O[1] - A[1])
    r = math.sqrt(OA[0] * OA[0] + OA[1] * OA[1])  # radius
    arc = createarc(O, A, C, r, segments)

    tData = OsmData()
    wayid = tData.addway()
    for point in arc:
        p = projections.to4326(point, "EPSG:3857")
        newid = tData.addnode()
        tData.nodes[newid][LON] = p[0]
        tData.nodes[newid][LAT] = p[1]
        tData.nodes[newid][TAG] = {}
        tData.ways[wayid][REF].append(newid)
    if params == 1:
        p2 = projections.to4326(O, "EPSG:3857")  # center
        p1 = projections.to4326((O[0] - r * 1.05, O[1]),
                                "EPSG:3857")  # axes points
        p3 = projections.to4326((O[0] + r * 1.05, O[1]), "EPSG:3857")
        p4 = projections.to4326((O[0], O[1] - r * 1.05), "EPSG:3857")
        p5 = projections.to4326((O[0], O[1] + r * 1.05), "EPSG:3857")
        wayid = tData.addway()
        newid = tData.addnode()
        tData.nodes[newid][LON] = p1[0]
        tData.nodes[newid][LAT] = p1[1]
        tData.nodes[newid][TAG] = {}
        tData.ways[wayid][REF].append(newid)
        newid2 = tData.addnode()
        tData.nodes[newid2][LON] = p2[0]
        tData.nodes[newid2][LAT] = p2[1]
        tData.nodes[newid2][TAG] = {}
        tData.ways[wayid][REF].append(newid2)
        newid = tData.addnode()
        tData.nodes[newid][LON] = p3[0]
        tData.nodes[newid][LAT] = p3[1]
        tData.nodes[newid][TAG] = {}
        tData.ways[wayid][REF].append(newid)
        wayid = tData.addway()
        newid = tData.addnode()
        tData.nodes[newid][LON] = p4[0]
        tData.nodes[newid][LAT] = p4[1]
        tData.nodes[newid][TAG] = {}
        tData.ways[wayid][REF].append(newid)
        tData.ways[wayid][REF].append(newid2)
        newid = tData.addnode()
        tData.nodes[newid][LON] = p5[0]
        tData.nodes[newid][LAT] = p5[1]
        tData.nodes[newid][TAG] = {}
        tData.ways[wayid][REF].append(newid)

    tData.addcomment("Done.")
    tData.write(sys.stdout)
    #f = open("out.txt", "w")
    #tData.write(f)
    #f.close()
    return 0
def main():
  if len(sys.argv) != 3:
    return 0
  wData = OsmData() # Way
  nData = OsmData() # Nodes
  wData.read(sys.stdin)
  wData.read(sys.stdin)
  nData.read(sys.stdin)
  radius = float(sys.argv[1])
  segments = int(sys.argv[2])
  
  nodes = []
  usednodes = set()
  for way in wData.ways.items():
    for key in nData.nodes.keys():
      if key in usednodes:
        continue
      try:
        index = way[1][REF].index(key)
      except ValueError:
        pass
      else:
        lastindex = len(way[1][REF]) - 1
        if way[1][REF][0] == way[1][REF][lastindex]: # polygon
          if index == 0:
            nodes.append([way[1][REF][lastindex-1], key, way[1][REF][index+1], way[0], index]) # previous node, node for fillet, next node, way
            usednodes.add(key)
          else:
            nodes.append([way[1][REF][index-1], key, way[1][REF][index+1], way[0], index])
            usednodes.add(key)
        else: # way
          if index > 0 and index < lastindex:
            nodes.append([way[1][REF][index-1], key, way[1][REF][index+1], way[0], index])
            usednodes.add(key)
  tData = OsmData()
  tData.mergedata(nData)
  tData.mergedata(wData)
  for pack in nodes:
    M = projections.from4326( (wData.nodes[pack[0]][LON], wData.nodes[pack[0]][LAT]), "EPSG:3857") # previous node
    O = projections.from4326( (wData.nodes[pack[1]][LON], wData.nodes[pack[1]][LAT]), "EPSG:3857") # center node
    N = projections.from4326( (wData.nodes[pack[2]][LON], wData.nodes[pack[2]][LAT]), "EPSG:3857") # next node
    r = radius / math.cos(math.radians(wData.nodes[pack[1]][LAT]))
    OM = (M[0] - O[0], M[1] - O[1])
    ON = (N[0] - O[0], N[1] - O[1])
    OMabs = math.sqrt(OM[0]*OM[0] + OM[1]*OM[1])
    ONabs = math.sqrt(ON[0]*ON[0] + ON[1]*ON[1])
    cosa = (OM[0]*ON[0] + OM[1]*ON[1]) / (OMabs * ONabs)
    OCabs = r / (math.sqrt((1 - cosa) / 2))
    OMnorm = (OM[0]/OMabs, OM[1]/OMabs)
    ONnorm = (ON[0]/ONabs, ON[1]/ONabs)
    bisectrix = (OMnorm[0] + ONnorm[0], OMnorm[1] + ONnorm[1])
    bisectrixabs = math.sqrt(bisectrix[0]*bisectrix[0] + bisectrix[1]*bisectrix[1])
    bisectrixnorm = (bisectrix[0]/bisectrixabs, bisectrix[1]/bisectrixabs)
    OC = (bisectrixnorm[0]*OCabs, bisectrixnorm[1]*OCabs)
    C = (O[0]+OC[0], O[1]+OC[1])

    P1 = project(OM, O, C)
    P2 = project(ON, O, C)
    arc = createarc(C, P1, P2, r, segments)
    arcref = []
    exists = int(segments/2)
    for point in range(len(arc)):
      p = projections.to4326(arc[point], "EPSG:3857")
      if point == exists:
        tData.nodes[pack[1]][ACTION] = MODIFY
        tData.nodes[pack[1]][LON] = p[0]
        tData.nodes[pack[1]][LAT] = p[1]
        arcref.append(pack[1])
      else:
        newid = tData.addnode()
        tData.nodes[newid][LON] = p[0]
        tData.nodes[newid][LAT] = p[1]
        tData.nodes[newid][TAG] = {}
        arcref.append(newid)

    way = tData.ways[pack[3]]
    way[ACTION] = MODIFY
    lastindex = len(way[REF]) - 1
    index = way[REF].index(pack[1])
    ref = way[REF][:]
    if way[REF][0] == way[REF][lastindex] and index == 0: # polygon
      way[REF] = arcref[:]
      way[REF] += (ref[1:lastindex])
      way[REF] += [(arcref[0])]
    else: # way
      way[REF] = ref[:index] + arcref + ref[index+1:]
    tData.ways[pack[3]] = way
  tData.addcomment("Done.")
  tData.write(sys.stdout)
  #f = open("out.txt", "w")
  #tData.write(f)
  #f.close()
  return 0
示例#8
0
def main():

    if len(sys.argv) != 2:
        return 0

    coords = (sys.argv[1].split(','))
    # lon = float(coords[0])
    # lat = float(coords[1])
    # coords_m = projections.from4326((lon,lat), "EPSG:3857")

    tData = OsmData()
    httpc = client()

    # text = httpc.request('http://pkk5.rosreestr.ru/arcgis/rest/services/Cadastre/CadastreSelected/MapServer/1/query?text=&geometry='+str(coords_m[0])+','+str(coords_m[1])+'&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&objectIds=&where=&time=&returnCountOnly=false&returnIdsOnly=false&returnGeometry=false&maxAllowableOffset=&outSR=&outFields=*&f=pjson')

    text = httpc.request('https://pkk.rosreestr.ru/api/features/1?text=' +
                         coords[1] + '%20' + coords[0] +
                         '&tolerance=4&limit=11')

    data = json.loads(text)
    if 'features' in data:
        ids = []
        for result in data['features']:
            #if len(result['value']) >= 11:
            try:
                ids.append(result['attrs']['id'])
            except KeyError:
                continue

        if len(ids) > 0:
            addresses = []
            for id in ids:
                #text = httpc.request('http://maps.rosreestr.ru/arcgis/rest/services/Cadastre/CadastreInfo/MapServer/2/query?f=json&where=PARCELID%20IN%20(%27'+id+'%27)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=FULLADDRESS,CATEGORY,UTIL_BY_DOC');

                text = httpc.request(
                    'https://pkk.rosreestr.ru/api/features/1/' + id)

                data = json.loads(text)

                if 'feature' in data:
                    address = {}
                    try:
                        s = data['feature']['attrs']['address'].split(',')
                        address['addr:housenumber'] = s.pop().strip()
                        address['addr:street'] = s.pop().strip()
                        address['addr:full'] = data['feature']['attrs'][
                            'address']
                        address['fixme'] = 'yes'
                    except KeyError:
                        continue
                    try:
                        #	address['category'] = feature['attributes']['CATEGORY']
                        address['utilization'] = data['feature']['attrs'][
                            'util_by_doc']
                    except KeyError:
                        pass
                    addresses.append(address)
                else:
                    tData.addcomment('Feature is empty')
                    continue
            count = len(addresses)
            if count == 1:
                nodeid = tData.addnode()
                tData.nodes[nodeid][LON] = coords[0]
                tData.nodes[nodeid][LAT] = coords[1]
                tData.nodes[nodeid][TAG] = addresses[0]
                comment = addresses[0]['addr:street'] + ', ' + addresses[0][
                    'addr:housenumber']
                if addresses[0]['utilization'] <> None:
                    comment += ' - ' + addresses[0]['utilization']
                tData.addcomment(comment)
            else:
                for i in range(count):
                    angle = 2 * math.pi * i / count
                    x = float(coords[0]) + 0.00001 * math.cos(angle)
                    y = float(coords[1]) + 0.00001 * math.sin(angle)
                    #node = projections.to4326((x, y), "EPSG:3857")
                    nodeid = tData.addnode()
                    tData.nodes[nodeid][LON] = x
                    tData.nodes[nodeid][LAT] = y
                    tData.nodes[nodeid][TAG] = addresses[i]
                    comment = addresses[i]['addr:street'] + ', ' + addresses[
                        i]['addr:housenumber']
                    if addresses[i]['utilization'] <> None:
                        comment += ' - ' + addresses[i]['utilization']
                    tData.addcomment(comment)
        else:
            tData.addcomment('Unknown error')
    else:
        tData.addcomment('Features is empty')
    tData.write(sys.stdout)
    return 0
示例#9
0
def main():
    if len(sys.argv) != 3:
        return 0
    wData = OsmData()  # Way
    nData = OsmData()  # Nodes
    wData.read(sys.stdin)
    wData.read(sys.stdin)
    nData.read(sys.stdin)
    radius = float(sys.argv[1])
    segments = int(sys.argv[2])

    nodes = []
    usednodes = set()
    for way in wData.ways.items():
        for key in nData.nodes.keys():
            if key in usednodes:
                continue
            try:
                index = way[1][REF].index(key)
            except ValueError:
                pass
            else:
                lastindex = len(way[1][REF]) - 1
                if way[1][REF][0] == way[1][REF][lastindex]:  # polygon
                    if index == 0:
                        nodes.append([
                            way[1][REF][lastindex - 1], key,
                            way[1][REF][index + 1], way[0], index
                        ])  # previous node, node for fillet, next node, way
                        usednodes.add(key)
                    else:
                        nodes.append([
                            way[1][REF][index - 1], key,
                            way[1][REF][index + 1], way[0], index
                        ])
                        usednodes.add(key)
                else:  # way
                    if index > 0 and index < lastindex:
                        nodes.append([
                            way[1][REF][index - 1], key,
                            way[1][REF][index + 1], way[0], index
                        ])
                        usednodes.add(key)
    tData = OsmData()
    tData.mergedata(nData)
    tData.mergedata(wData)
    for pack in nodes:
        M = projections.from4326(
            (wData.nodes[pack[0]][LON], wData.nodes[pack[0]][LAT]),
            "EPSG:3857")  # previous node
        O = projections.from4326(
            (wData.nodes[pack[1]][LON], wData.nodes[pack[1]][LAT]),
            "EPSG:3857")  # center node
        N = projections.from4326(
            (wData.nodes[pack[2]][LON], wData.nodes[pack[2]][LAT]),
            "EPSG:3857")  # next node
        r = radius / math.cos(math.radians(wData.nodes[pack[1]][LAT]))
        OM = (M[0] - O[0], M[1] - O[1])
        ON = (N[0] - O[0], N[1] - O[1])
        OMabs = math.sqrt(OM[0] * OM[0] + OM[1] * OM[1])
        ONabs = math.sqrt(ON[0] * ON[0] + ON[1] * ON[1])
        cosa = (OM[0] * ON[0] + OM[1] * ON[1]) / (OMabs * ONabs)
        OCabs = r / (math.sqrt((1 - cosa) / 2))
        OMnorm = (OM[0] / OMabs, OM[1] / OMabs)
        ONnorm = (ON[0] / ONabs, ON[1] / ONabs)
        bisectrix = (OMnorm[0] + ONnorm[0], OMnorm[1] + ONnorm[1])
        bisectrixabs = math.sqrt(bisectrix[0] * bisectrix[0] +
                                 bisectrix[1] * bisectrix[1])
        bisectrixnorm = (bisectrix[0] / bisectrixabs,
                         bisectrix[1] / bisectrixabs)
        OC = (bisectrixnorm[0] * OCabs, bisectrixnorm[1] * OCabs)
        C = (O[0] + OC[0], O[1] + OC[1])

        P1 = project(OM, O, C)
        P2 = project(ON, O, C)
        arc = createarc(C, P1, P2, r, segments)
        arcref = []
        exists = int(segments / 2)
        for point in range(len(arc)):
            p = projections.to4326(arc[point], "EPSG:3857")
            if point == exists:
                tData.nodes[pack[1]][ACTION] = MODIFY
                tData.nodes[pack[1]][LON] = p[0]
                tData.nodes[pack[1]][LAT] = p[1]
                arcref.append(pack[1])
            else:
                newid = tData.addnode()
                tData.nodes[newid][LON] = p[0]
                tData.nodes[newid][LAT] = p[1]
                tData.nodes[newid][TAG] = {}
                arcref.append(newid)

        way = tData.ways[pack[3]]
        way[ACTION] = MODIFY
        lastindex = len(way[REF]) - 1
        index = way[REF].index(pack[1])
        ref = way[REF][:]
        if way[REF][0] == way[REF][lastindex] and index == 0:  # polygon
            way[REF] = arcref[:]
            way[REF] += (ref[1:lastindex])
            way[REF] += [(arcref[0])]
        else:  # way
            way[REF] = ref[:index] + arcref + ref[index + 1:]
        tData.ways[pack[3]] = way
    tData.addcomment("Done.")
    tData.write(sys.stdout)
    #f = open("out.txt", "w")
    #tData.write(f)
    #f.close()
    return 0