I am tried to display geojson file (converted from AutoCAD file to geojson) as the Second layer (first layer maps OSM ).
But geojson content occupies entire maps, not in a specific location.
How can we change coordinates in geojson file or how to reduce the height and width of geojson(second layer)? Please find below the Sample geojson file...
{
"type": "FeatureCollection",
"name": "entities",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [
{
"type": "Feature",
"properties": {
"Layer": "entities",
"SubClasses": "AcDbEntity:AcDbPolyline",
"EntityHandle": "1FFF0038"
},
"geometry": {
"type": "LineString",
"coordinates": [
[
0,
0
],
[
0,
319.9694
],
[
361.2444,
319.9694
],
[
361.2444,
0
],
[
0,
0
]
]
}
},
{
"type": "Feature",
"properties": {
"Layer": "entities",
"SubClasses": "AcDbEntity:AcDbPolyline",
"EntityHandle": "1FFF011D"
},
"geometry": {
"type": "LineString",
"coordinates": [
[
0,
252.0448
],
[
0,
319.9694
],
[
361.2444,
319.9278
],
[
361.2444,
142.5544
],
[
0,
142.5544
],
[
0,
197.4439
],
[
9.1842,
197.4439
],
[
9.1842,
151.7295
],
[
352.0603,
151.7295
],
[
352.0603,
310.7537
],
[
9.1842,
310.7932
],
[
9.1842,
252.0448
],
[
0,
252.0448
]
]
}
}
]
}
TL;DR: You're confusing the coordinate systems.
Coordinates in GeoJSON data refer to degrees of longitude in the X axis, and degrees of longitude in the Y axis. This is by definition . When these coordinates are mapped onto a cartesian plane, that becomes an equirectangular projection .
By contrast, coordinates in AutoCAD (or pretty much any other CAD software) usually refer to meters (or imperial feet) when there's an architect between the chair and the keyboard; also they usually refer to millimeters/centimeters (or tenths of an imperial inch) when there's a mechanical engineer between chair and keyboard.
So a line from -53, -10
to 0, 40
can be either a flight from Brazil to Spain, a 72-meter-long wall, or a 72mm length of cable.
Since you are using GeoJSON, and GeoJSON only cares about geographical coordinates in degrees of latitude/longitude, any software will assume that your coordinates are degrees of lat/long, and display them accordingly. The default for Leaflet is to project the data onto Web Mercator , and clip anything above/below +90/-90 degrees of latitude. This is to be expected.
So, the coordinate systems are wrong, what to do now? I see two approaches:
Change the CAD coordinates so they refer to lat-lng. This process is known as georeferencing . The specifics differ and can be complicated, sosearching through GIS StackExchange might be a good start.
Tell Leaflet to display non-geographical coordinates. Read the Leaflet tutorial on the topic , and use the crs: L.CRS.Simple
option when instantiating your map. That should make your data display (more) correctly, but remember that GeoJSON is not an appropriate data format for non-geographical data .
In any case, be aware of your coordinate system .
Finally i got solution by unprojecting CRS EPSG3857 then the same geojson file working fine in leaflet.Thanks..
By adding,
L.CRS.EPSG3857.unproject(point) // where point is coords.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.