span8
span4
span8
span4
There are different methods of converting rasters to CAD formats using FME.The method covered in this article will use the customPotraceCallertransformer.Potrace(™)is a tool that is used for tracing bitmaps and creating vectors.In this example,we will take a JPEG screenshot of a neighbourhood and vectorize the buildings to output an AutoCAD dwg file.
osm-raster-to-cad-vector-example.fmw
Add a JPEG (Joint Photographic Experts Group) Reader to a blank canvas.Browse to the osm.jpg dataset.In the parameters for Feature Type Name(s) select From File Name(s).
Inspect the data with the FME Data Inspector.We have a screenshot of a map section in Burnaby,BC taken from Open Street Map.We would like to create polygons from the building shapes so we will need to determine the color range.Click on any section of any of the grey building shapes,including the darker border.Looking at the Feature Information pane,take note of Band 0 (RED8) values while clicking over the building polygons,this will be the values for the RasterExpressionEvaluator.
Click on any of the buildings,and take note of the Band 0 (RED8) values in the Feature Information Pane in the Data Inspector
Back in FME Desktop,using the RasterExpressionEvaluator,we will need to create a Band Expression for Red8.In the Parameters set the Interpretation to Red8,for the Expression,click the [...] to open the Arithmetic Editor - ‘Raster Expression'.While using the Pick Screen Color,we determined that the Value of Red is between 200 and 235 depending on where you put your mouse.But the Red Value of the area surrounding the building is 240 and up.We need to create an expression that states if Bands A[0-2] is greater than Red Value 200,but Less than 235,determine that it is a building,which looks like:
if(A[0]>200&&A[0]<235&&A[1]>200&&A[1]<235&&A[2]>200&&A[2]<235,0,255)
RasterExpressionEvaluator expression for color range of buildings
To set NoData for the remainder of the pixels in the image,use the RasterBandNodataSetter transformer.Set the Nodata Value to 255.
DownloadPotrace(™)and unzip the download file.Then add thePotraceCallercustom transformer.In the parameters,set the Potrace.exe Location to the location where you downloaded Potrace,and select the Potrace.exe file.Set the Remove Speckles Up To,to 500,this will remove the anti-aliasing that occurs in the JPEG to create a truer vector line.Add an Inspector and run the translation
Inspecting the outlines created using the PotraceCaller,the lines are in the correct area but are very pixelated.To smooth out this pixelization,添加一个概括变压器。In the parameters,set the Algorithm to Douglas (Generalize),this algorithm removes vertices that cause a deviation of less than the Generalization Tolerance,but the location of the remaining vertices stay the same.Set the Generalization Tolerance (>=0) to 10,you can play around with this,the lower the number the more of the shape is preserved,the higher the number the less of the shape is preserved.Since most of the buildings are square,a generalization tolerance of 10 will work,only a couple buildings in the upper right corner will lose their shape.
Comparison of different Generalization Tolerances using the Douglas Algorithm in the Generalizer transformer.
Add a DWGStyler transformer,set the color to Red.Then enable Areas,and set the Area Entity Type to MPolygon With Fill Pattern.For the Fill Pattern Name,select the wide brick pattern,AR-B816.
Add an AutoDesk AutoCAD DWG/DXF Writer to the canvas.Name the Dataset OSM.dwg,then in the parameters,change the Layer Name to Buildings.Run the translation,view the output OSM.dwg file in AutoCAD to see the area fill pattern.
Styled OSM.dwg output in AutoDesk AutoCAD
The data used in this article is from an open data license provided by© OpenStreetMap contributors
If(expression,value,value)The firstargument is A[0]>200&&A[0]<235&&A[1]>200&&A[1]<235&&A[2]>200&&A[2]<235 this argument looks for values between 200 and 235 for Bands0,1 and 2.
The second argument sets the buildings to 0,which makes them black.
The third argument sets everything except the buildings to 255,which is red because it is on the Red8 band.
© 2019 亚搏在线Safe Software Inc |Legal