def check_points_cover_start_end(points, lines):
    '''

    :param points: Shapely point geometries
    :param lines:Shapely linestrings
    :return:
    '''

    all_start_end_nodes = create_start_end_pts(lines)

    bad_points = []
    good_points = []
    if len(points) > 1:
        for pt in points:
            if pt.touches(all_start_end_nodes):
                print "touches"
            if pt.disjoint(all_start_end_nodes):
                print "disjoint" # 2 nodes
                bad_points.append(pt)
            if pt.equals(all_start_end_nodes):
                print "equals"
            if pt.within(all_start_end_nodes):
                print "within" # all our nodes on start or end
            if pt.intersects(all_start_end_nodes):
                print "intersects"
                good_points.append(pt)
    else:
        if points.intersects(all_start_end_nodes):
            print "intersects"
            good_points.append(points)
        if points.disjoint(all_start_end_nodes):
            print "disjoint"
            good_points.append(points)


    if len(bad_points) > 1:
        print "oh no 1 or more points are NOT on a start or end node"
        out_geoj(bad_points, '../geodata/points_bad.geojson')
        out_geoj(good_points, '../geodata/points_good.geojson')

    elif len(bad_points) == 1:
        print "oh no your input single point is NOT on start or end node"

    else:
        print "super all points are located on a start or end node" \
              "NOTE point duplicates are NOT checked"
Exemple #2
0
def check_points_cover_start_end(points, lines):
    '''

    :param points: Shapely point geometries
    :param lines:Shapely linestrings
    :return:
    '''

    all_start_end_nodes = create_start_end_pts(lines)

    bad_points = []
    good_points = []
    if len(points) > 1:
        for pt in points:
            if pt.touches(all_start_end_nodes):
                print "touches"
            if pt.disjoint(all_start_end_nodes):
                print "disjoint"  # 2 nodes
                bad_points.append(pt)
            if pt.equals(all_start_end_nodes):
                print "equals"
            if pt.within(all_start_end_nodes):
                print "within"  # all our nodes on start or end
            if pt.intersects(all_start_end_nodes):
                print "intersects"
                good_points.append(pt)
    else:
        if points.intersects(all_start_end_nodes):
            print "intersects"
            good_points.append(points)
        if points.disjoint(all_start_end_nodes):
            print "disjoint"
            good_points.append(points)

    if len(bad_points) > 1:
        print "oh no 1 or more points are NOT on a start or end node"
        out_geoj(bad_points, '../geodata/points_bad.geojson')
        out_geoj(good_points, '../geodata/points_good.geojson')

    elif len(bad_points) == 1:
        print "oh no your input single point is NOT on start or end node"

    else:
        print "super all points are located on a start or end node" \
              "NOTE point duplicates are NOT checked"
            # add valid geometry to list
            plys.append(g)
    # convert new polygons into a new MultiPolygon
    out_new_valid_multi = MultiPolygon(plys)
    return out_new_valid_multi


if __name__ == "__main__":

    # input NOAA Shapefile
    shp = realpath("../geodata/temp-all-warn-week.shp")

    # output union_dissolve results as GeoJSON
    out_geojson_file = realpath("../geodata/ch06-03_union_dissolve.geojson")

    out_wkt_js = realpath("ol3/data/ch06-03_results_union.js")

    # input Shapefile and convert to Shapely geometries
    shply_geom = create_shapes(shp)

    # Check the Shapely geometries if they are valid if not fix them
    new_valid_geom = check_geom(shply_geom)

    # run our union with dissolve
    dissolve_result = cascaded_union(new_valid_geom)

    # output the resulting union dissolved polygons to GeoJSON file
    out_geoj(dissolve_result, out_geojson_file)

    write_wkt(out_wkt_js, dissolve_result)
overlap_found = False

for line in shp1_lines:
    if line.equals(shp2_lines_overlap):
        print "equals"
        overlap_found = True
    if line.within(shp2_lines_overlap):
        print "within"
        overlap_found = True

# output the overlapping linestrings
if overlap_found:
    print "now exporting overlaps to GeoJSON"
    out_int = shp1_lines.intersection(shp2_lines_overlap)
    out_geoj(out_int, '../geodata/overlapping_lines.geojson')

    # create final linestring only list of overlapping lines
    # uses a pyhton list comprehension expression
    # only export the linestrings Shapely also creates  2 Points
    # where the linestrings cross and touch
    final = [feature for feature in out_int if feature.geom_type == "LineString"]

    # code if you do not want to use a list comprehension expresion
    # final = []
    # for f in out_int:
    #     if f.geom_type == "LineString":
    #         final.append(f)

    # export final list of geometries to GeoJSON
    out_geoj(final, '../geodata/final_overlaps.geojson')
Exemple #5
0
overlap_found = False

for line in shp1_lines:
    if line.equals(shp2_lines_overlap):
        print "equals"
        overlap_found = True
    if line.within(shp2_lines_overlap):
        print "within"
        overlap_found = True

# output the overlapping linestrings
if overlap_found:
    print "now exporting overlaps to GeoJSON"
    out_int = shp1_lines.intersection(shp2_lines_overlap)
    out_geoj(out_int, '../geodata/overlapping_lines.geojson')

    # create final linestring only list of overlapping lines
    # uses a pyhton list comprehension expression
    # only export the linestrings Shapely also creates  2 Points
    # where the linestrings cross and touch
    final = [
        feature for feature in out_int if feature.geom_type == "LineString"
    ]

    # code if you do not want to use a list comprehension expresion
    # final = []
    # for f in out_int:
    #     if f.geom_type == "LineString":
    #         final.append(f)
shp2_polys = create_polys(shp2_data)


# run the difference and intersection
res_difference = shp1_polys.difference(shp2_polys)
res_intersection = shp1_polys.intersection(shp2_polys)


def create_out(res1, res2):
    """

    :param res1: input feature
    :param res2: identity feature
    :return: MultiPolygon identity results
    """
    identity_geoms = []

    for g1 in res1:
        identity_geoms.append(g1)
    for g2 in res2:
        identity_geoms.append(g2)

    out_identity = MultiPolygon(identity_geoms)
    return out_identity

# combine the difference and intersection polygons into results
result_identity = create_out(res_difference, res_intersection)

# export identity results to a GeoJSON
out_geoj(result_identity, out_geojson_file)
        # go through each line added first to second
        # then second to third and so on
        shply_lines = lines[:i] + lines[i + 1:]
        # 0 is start point and -1 is end point
        # run through
        for start_end in [0, -1]:
            # convert line to point
            node = Point(line.coords[start_end])
            # Return True if any element of the iterable is true.
            # https://docs.python.org/2/library/functions.html#any
            # python boolean evaluation comparison
            if any(node.touches(next_line) for next_line in shply_lines):
                continue
            else:
                list_dangles.append(node)
    return list_dangles


# convert our Shapely MultiLineString to list
list_lines = [line for line in shp1_lines]

# find those dangles
result_dangles = find_dangles(list_lines)

# return our results
if len(result_dangles) >= 1:
    print "yes we found some dangles exporting to GeoJSON"
    out_geoj(result_dangles, '../geodata/dangles.geojson')
else:
    print "no dangles found"
shp2_polys = create_polys(shp2_data)

# run the difference and intersection
res_difference = shp1_polys.difference(shp2_polys)
res_intersection = shp1_polys.intersection(shp2_polys)


def create_out(res1, res2):
    """

    :param res1: input feature
    :param res2: identity feature
    :return: MultiPolygon identity results
    """
    identity_geoms = []

    for g1 in res1:
        identity_geoms.append(g1)
    for g2 in res2:
        identity_geoms.append(g2)

    out_identity = MultiPolygon(identity_geoms)
    return out_identity


# combine the difference and intersection polygons into results
result_identity = create_out(res_difference, res_intersection)

# export identity results to a GeoJSON
out_geoj(result_identity, out_geojson_file)
        # each line gets a number
        # go through each line added first to second
        # then second to third and so on
        shply_lines = lines[:i] + lines[i+1:]
        # 0 is start point and -1 is end point
        # run through
        for start_end in [0, -1]:
            # convert line to point
            node = Point(line.coords[start_end])
            # Return True if any element of the iterable is true.
            # https://docs.python.org/2/library/functions.html#any
            # python boolean evaluation comparison
            if any(node.touches(next_line) for next_line in shply_lines):
                continue
            else:
                list_dangles.append(node)
    return list_dangles

# convert our Shapely MultiLineString to list
list_lines = [line for line in shp1_lines]

# find those dangles
result_dangles = find_dangles(list_lines)

# return our results
if len(result_dangles) >= 1:
    print "yes we found some dangles exporting to GeoJSON"
    out_geoj(result_dangles, '../geodata/dangles.geojson')
else:
    print "no dangles found"
    # create our centroids for each polygon
    list_centroids = [x.centroid for x in polygons]

    # list to store all of our centroids within tolerance
    good_points = []

    for centroid in list_centroids:
        for line in lines:
            # calculate point location on line nearest to centroid
            pt_interpolate = line.interpolate(line.project(centroid))
            # determine distance between 2 cartesian points
            # that are less than the tolerance value in meters
            if centroid.distance(pt_interpolate) > tolerance:
                print "to far  " + str(centroid.distance(pt_interpolate))
            else:
                print "hey your in  " + str(centroid.distance(pt_interpolate))
                good_points.append(centroid)

    if len(good_points) > 1:
        return good_points
    else:
        print "sorry no centroids found within your tolerance of " + str(tolerance)

# run our function to get a list of centroids within tolerance
result_points = within_tolerance(shply_polys, shp1_lines, 20000)

if result_points:
    out_geoj(result_points, '../geodata/centroids_within_tolerance.geojson')
else:
    print "sorry cannot export GeoJSON of Nothing"
Exemple #11
0
    # list to store all of our centroids within tolerance
    good_points = []

    for centroid in list_centroids:
        for line in lines:
            # calculate point location on line nearest to centroid
            pt_interpolate = line.interpolate(line.project(centroid))
            # determine distance between 2 cartesian points
            # that are less than the tolerance value in meters
            if centroid.distance(pt_interpolate) > tolerance:
                print "to far  " + str(centroid.distance(pt_interpolate))
            else:
                print "hey your in  " + str(centroid.distance(pt_interpolate))
                good_points.append(centroid)

    if len(good_points) > 1:
        return good_points
    else:
        print "sorry no centroids found within your tolerance of " + str(
            tolerance)


# run our function to get a list of centroids within tolerance
result_points = within_tolerance(shply_polys, shp1_lines, 20000)

if result_points:
    out_geoj(result_points, '../geodata/centroids_within_tolerance.geojson')
else:
    print "sorry cannot export GeoJSON of Nothing"