I have a shapefile of polylines for trails, and I need to convert them all to be polygons that are 8 ft wide (4 ft from the center of each side of the polyline). I tried a following a few other posts that I thought were doing the same thing, but I always just ended up a big blob of color.
[GIS] Converting polyline to fixed width polygon using QGIS
bufferlinepolygonqgis
Related Solutions
Matthias,
The pyshp syntax requires nested Python lists containing coordinates as floats. Your current approach is a string which simply looks like the syntax.
The quick, but not recommended, method would be to eval your string (very insecure):
linestr = "[[[-94,-49.1152],[-94.45451,-49],[-93,-49.30391],[-94,-49.1152]]]"
w.line(parts=eval(linestr))
The proper way would be to cast each coordinate pair to floats and append to a list:
coords=[["-94","-49.1152"],["-94.45451","-49"],["-93","-49.30391"],["-94","-49.1152"]]
line_parts = []
line = []
for x,y in coords:
line.append([float(x),float(y)])
line_parts.append(line)
w.line(parts=line_parts)
You should send a small example of such DXF file. It looks like DXF driver really does not behave as documented. I made a simple test by digitizing a closing triangle with four coordinates as a polygon and as a linestring
POLYGON (( 616 442, 804 551, 764 387, 616 442 ))
LINESTRING ( 616 442, 804 551, 764 387, 616 442 )
I made a roundtrip by saving geometry into shapefile -> convert shapefile into DXF with ogr2ogr -> checking the DXF file with ogrinfo. If DXF driver behaves as documented both DXF files should contain a polygon. However, that is not the case with the closed linestring
ogrinfo -al line_test.dxf
INFO: Open of `line_test.dxf'
using driver `DXF' successful.
Layer name: entities
Geometry: Unknown (any)
Feature Count: 1
Extent: (616.000000, 387.000000) - (804.000000, 551.000000)
Layer SRS WKT:
(unknown)
Layer: String (0.0)
SubClasses: String (0.0)
ExtendedEntity: String (0.0)
Linetype: String (0.0)
EntityHandle: String (0.0)
Text: String (0.0)
OGRFeature(entities):0
Layer (String) = 0
SubClasses (String) = AcDbEntity:AcDbPolyline
ExtendedEntity (String) = (null)
Linetype (String) = (null)
EntityHandle (String) = 20000
Text (String) = (null)
Style = PEN(c:#000000)
LINESTRING (616 442,804 551,764 387,616 442)
Unfortunately this does not solve your problem but only confirms it. Moreover, the documentation of DXF driver seems to be wrong in other places as well. It claims that GDAL is writing polygons as LWPOLYLINE. However, from the DXF which I converted from the polygon shape I can find that entity HATCH is used:
This is how GDAL creates a polygon:
ENTITIES
0
HATCH
5
20000
8
0
100
AcDbEntity
100
AcDbHatch
This is how a closed linestring was defined:
ENTITIES
0
LWPOLYLINE
5
20000
8
0
100
AcDbEntity
100
AcDbPolyline
70
1
90
4
For me it feels like you don't do anything wrong and you should ask from the gdal-dev mailing list if you have found a bug in the DXF driver or in the documentation. Attach a small DXF sample, a closed triangle as I used in my test should be perfect.
Best Answer
I can't tell if "blob of color" means all the trails are now joined together, or that it takes a lot of screen area.
If the former, see if you have
dissolve buffer results
checked, as it will dissolve all the 8 ft wide polygons representing individual trails into one.If the latter, it might be a symbology problem, where you have set the outline too thick, try thinning it, or changing the border of the polygons from millimeters to map units.