Ejemplo n.º 1
0
def test_polygon_from_hatch_hole_in_hole():
    hatch = factory.new("HATCH")
    paths = hatch.paths
    paths.add_polyline_path(square(10), flags=1)
    paths.add_polyline_path(translate(square(8), (1, 1)), flags=0)
    paths.add_polyline_path(translate(square(6), (2, 2)), flags=0)
    mapping = geo.proxy(hatch).__geo_interface__
    assert mapping["type"] == "Polygon"
    assert len(mapping["coordinates"]) == 2, "inner hole should be removed"

    mapping = geo.proxy(hatch, force_line_string=True).__geo_interface__
    assert mapping["type"] == "MultiLineString"
    assert len(mapping["coordinates"]) == 3, "inner hole should not be removed"
Ejemplo n.º 2
0
def test_polygon_from_hatch_hole_in_hole():
    hatch = factory.new('HATCH')
    paths = hatch.paths
    paths.add_polyline_path(square(10), flags=1)
    paths.add_polyline_path(translate(square(8), (1, 1)), flags=0)
    paths.add_polyline_path(translate(square(6), (2, 2)), flags=0)
    mapping = geo.proxy(hatch).__geo_interface__
    assert mapping['type'] == 'Polygon'
    assert len(mapping['coordinates']) == 2, 'inner hole should be removed'

    mapping = geo.proxy(hatch, force_line_string=True).__geo_interface__
    assert mapping['type'] == 'MultiLineString'
    assert len(mapping['coordinates']) == 3, 'inner hole should not be removed'
Ejemplo n.º 3
0
def test_three_polygons_from_one_hatch():
    hatch = factory.new('HATCH')
    paths = hatch.paths
    paths.add_polyline_path(square(1), flags=1)
    paths.add_polyline_path(translate(square(1), (3, 1)), flags=1)
    paths.add_polyline_path(translate(square(1), (6, 2)), flags=1)
    mapping = geo.proxy(hatch).__geo_interface__
    assert mapping['type'] == 'MultiPolygon'
    assert len(mapping['coordinates']) == 3
Ejemplo n.º 4
0
def test_arc_geo_proxy_wcs_to_crs():
    arc = factory.new(
        "ARC",
        dxfattribs={
            "start_angle": 0,
            "end_angle": 90,
        },
    )
    geo_proxy = geo.proxy(arc)
    geo_proxy.wcs_to_crs(Matrix44())
    assert len(geo_proxy.__geo_interface__["coordinates"][0]) > 1
Ejemplo n.º 5
0
def export_geojson(entity, m):
    # Convert DXF entity into a GeoProxy object:
    geo_proxy = geo.proxy(entity)
    # Transform DXF WCS coordinates into CRS coordinates:
    geo_proxy.wcs_to_crs(m)
    # Transform 2D map projection EPSG:3395 into globe (polar)
    # representation EPSG:4326
    geo_proxy.map_to_globe()
    # Export GeoJSON data:
    name = entity.dxf.layer + ".geojson"
    with open(TRACK_DATA / name, "wt", encoding="utf8") as fp:
        json.dump(geo_proxy.__geo_interface__, fp, indent=2)
Ejemplo n.º 6
0
def test_valid_hatch():
    hatch = factory.new('HATCH')
    paths = hatch.paths
    paths.add_polyline_path(square(10), flags=const.BOUNDARY_PATH_EXTERNAL)
    paths.add_polyline_path(translate(square(3), (1, 1)),
                            flags=const.BOUNDARY_PATH_DEFAULT)
    paths.add_polyline_path(translate(square(3), (5, 1)),
                            flags=const.BOUNDARY_PATH_DEFAULT)
    p = geo.proxy(hatch)
    polygon = shapely_geometry.shape(p)
    assert polygon.is_valid is True

    p.filter(validate)
    assert p.root != {}
Ejemplo n.º 7
0
def test_invalid_hatch_with_intersecting_holes():
    hatch = factory.new('HATCH')
    paths = hatch.paths
    paths.add_polyline_path(square(10),
                            flags=const.BOUNDARY_PATH_EXTERNAL)
    paths.add_polyline_path(translate(square(3), (1, 1)),
                            flags=const.BOUNDARY_PATH_DEFAULT)
    paths.add_polyline_path(translate(square(3), (2, 2)),
                            flags=const.BOUNDARY_PATH_DEFAULT)
    p = geo.proxy(hatch)
    polygon = shapely_geometry.shape(p)
    assert polygon.is_valid is False

    p.filter(validate)
    assert p.root == {}
Ejemplo n.º 8
0
def test_resolved_hatch_with_intersecting_holes():
    hatch = factory.new('HATCH')
    paths = hatch.paths
    paths.add_polyline_path(square(10), flags=const.BOUNDARY_PATH_EXTERNAL)
    paths.add_polyline_path(translate(square(3), (1, 1)),
                            flags=const.BOUNDARY_PATH_DEFAULT)
    paths.add_polyline_path(translate(square(3), (2, 2)),
                            flags=const.BOUNDARY_PATH_DEFAULT)
    p = geo.proxy(hatch)
    # Overlapping holes already resolved by fast_bbox_detection()
    polygon = shapely_geometry.shape(p)
    assert polygon.is_valid is True

    p.filter(validate)
    assert p.root['type'] == 'Polygon'
    assert len(p.root['coordinates']) == 2