1

I had an AutoCAD drawing of a floor plan. I imported it to python using Fiona and checked the metadata. The CRS is empty. When I checked the coordinates for the geometry, it was in the following form,

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "id": "0",
        "properties": {
            "A-WALL__ID": null
        },
        "geometry": {
            "type": "LineString",
            "coordinates": [
                [5319.568084840497, 5864.945849450571, 0.0],
                [5319.568084840497, 5882.945849450571, 0.0]
            ]
        }
    }, {
        "type": "Feature",
        "id": "1",
        "properties": {
            "A-WALL__ID": null
        },
        "geometry": {
            "type": "LineString",
            "coordinates": [
                [4767.568084840497, 5863.945849450571, 0.0],
                [4767.568084840497, 5882.945849450571, 0.0]
            ]
        }
    }
]
}

I imported the AutoCAD file in following way,

c = fiona.open("level0dwg.dxf", 'r')
c.meta

Following was the output,

{'driver': 'DXF',
 'schema': {'properties': OrderedDict([('Layer', 'str'),
               ('PaperSpace', 'int'),
               ('SubClasses', 'str'),
               ('Linetype', 'str'),
               ('EntityHandle', 'str'),
               ('Text', 'str')]),
  'geometry': 'Unknown'},
 'crs': {},
 'crs_wkt': ''}

I am confused as in what is this coordinate system. Is it pixel-based or something like that? and how can I transform it to WGS84 system with lat-longs to place it on the map? The AutoCAD file is not georeferenced.

Is there a way to do this in Python?

I want to georefer the DWG file to place it on the map using Python. I have been stuck at this issue for quite some time now.

1

The coordinate system could be anything. It could be a local coordinate system, it could be simply nothing, other than a drawing in meters/feet.(or cms, who knows).

Georeferencing would need a lot of information about the drawing, including units, dimensions (ie: Is it a rectnagle or a square? Rotation? Is it aligned north/south. who knows. That makes achieving that in python very difficult. In order to georeference the drawing, you will need known control points to align points in the drawing to. Here for reference https://docs.qgis.org/2.18/en/docs/training_manual/forestry/map_georeferencing.html

I would personally abandon the idea of georeferencing using code, and simply find out what coord system the drawing was captured in. It is actually really easy for an AutoCAD user to capture a coordinate system for a drawing. https://knowledge.autodesk.com/support/autocad-map-3d/learn-explore/caas/CloudHelp/cloudhelp/2017/ENU/MAP3D-Use/files/GUID-8A02D384-B075-4459-8E23-ED7D1C0F3D8F-htm.html

They should be doing this as part of their drawing managament, even for buildings/floorplans.

If you can't you might be better off manually georeferencing using the method linked above in QGIS. Given that its a floor plan, of which I assume an existing building, you may be able to do this based off of an aerial photo or similar. Depends on the scale/size of the building etc.

| improve this answer | |
  • Thank you for your reply. It is very useful. There are a few points I'd like to mention. I know the location of the floor plan. I have done the georeferencing part using qgis or ArcGIS using control points. I cannot use these software for georeferncing. Is there a way to use 2 or more control points for georeferencing in python? I found affine transformer of shapely..Is that of any use here? Thanks a lot for the cooperation! – Rahul Choudhary Oct 15 at 9:56
  • assuming the drawing is evenly distributed (that is, the change in distance and angle is the same for each point on the map) you could try warping. community.esri.com/thread/17303 again, this will be arcpy, or there will probably be a PyQGIS libraries involved. If these can't be used then have a look at numpy libraries. also maybe read this link stackoverflow.com/questions/29924150/… – nr_aus Oct 16 at 1:29
  • I will walk you through how I achieved it using ArcGIS Pro. I uploaded the floor plan drawing in the software, opened georeferencer, used 2 control points and It was gereferenced. But since I cannot use any software in our webapp, I want to do it programmatically. I am looking for a some library in python where I can choose 2 points on dwg and provide lat-longs for them and then transform the whole dwg based on these two points and export it as geojson. If there is a way to achieve this whole process, then it would solve a big chunk of issue we are facing here. Thanks for the links though. – Rahul Choudhary Oct 16 at 4:44
  • The thing is, The DWG is not georeferenced at all. So there is no CRS for it. Although I know the location of the building and want to georefer to that location and export it as geojson. – Rahul Choudhary Oct 16 at 4:47
0

Do you know where the model should be located? That would be helpful. It could be a Gauss- Krüger coordinate system. It happens often that AutoCAD models use a normal local coordinate system without any CRS relation. In that case you must do a reprojection knowing the right "global" orign.

| improve this answer | |
  • I know the location of the building. Its in USA, I know the lat longs of the building also. I want to use them as control points. Is there a way to georefer the file using control points in python? Any method will work that does not require direct use of a dedicated software to do so. Thanks in advance! – Rahul Choudhary Oct 15 at 10:00
  • In QGIS you could try v.transform. It lets you perform affine transformations. – DG85 Oct 15 at 12:33
  • I would work in a UTM coordinate system first. If the model should fit, you can transform it to WGS84. – DG85 Oct 15 at 12:41
  • The thing is, The DWG is not georeferenced at all. So there is no CRS for it. Although I know the location of the building and want to georefer to that location and export it as geojson. – Rahul Choudhary Oct 16 at 4:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.