mledoze / countries

World countries in JSON, CSV, XML and Yaml. Any help is welcome!

Home Page:https://mledoze.github.io/countries/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Black Hole effect in some countries

chema-mengibar opened this issue · comments

HI, thanks for this project.
I´m trying to load the country boundaries in Blender with Python.
I have one function to translate the lat and lon to xyz :

    self.EARTH = 2

    def simpleCoorToXyz(  self, _lat, _lon, _r ):

        tLon = _lon * pi/180
        tLat = _lat * pi/180

        x = cos( tLat ) * cos( tLon ) * self.EARTH
        y = cos( tLat ) * sin( tLon ) * self.EARTH
        z = sin( tLat ) * self.EARTH

        return [ x, y, z ]

The proble is that in some sides the countris will be deformed.
Any idea?

blender-006-gml-a-0000

blender-006-gml-a-0002

Thanks again

Have you tried viewing data with something known to be reliable to check that problem is not caused by your implementation?

commented

This might be 2 years old but I got a similar issue recently. The valid range of latitude is -90...90, but the max range of longitude is -180...180, so if you're using something that takes the opposite order from the geojson in this package (which uses long, lat), you will not only find the shapes drawn to be rotated but also skewed such as this.

@mtimofiiv do you think there is a problem with this dataset or with the implementation of @chema-mengibar?

commented

@mledoze I don't think there is a problem here TBH, it's perfect as-is and the proof is that the Github preview of the GeoJSON is correct which plots the GeoJSON on a Mapbox map. The GeoJSON spec calls for [ long, lat ] coordinate values and not [ lat, long ]. Unfortunately, many maps use the opposite:

https://leafletjs.com/reference-1.6.0.html#latlng
https://developers.google.com/maps/documentation/javascript/reference/coordinates#LatLng

It's a nuisance for sure to have to reverse the coordinates for use on a map, but both Leaflet and Google Maps support using the actual GeoJSON instead of plotting the polygons yourself.

If you must absolutely plot the polygon yourself, it can be done via a function like this one I created for my implementation which accepts a coordinates array and recursively reverses the coordinate order:

const reverseLatLong = geodata => {
  if (!geodata) return geodata

  if (
    typeof geodata[0] === 'number' && typeof geodata[1] === 'number'
  ) return [ geodata[1], geodata[0] ]

  const reversedSet = []

  for (const coords of geodata) {
    reversedSet.push(reverseLatLong(coords))
  }

  return reversedSet
}

Hi, everybody,

I´m really sorry for the delay (2 years) :_)
The problem was exactly the one described by mtimofiiv, simply change the order of "lon" and "lat".
When changing the values, the shapes are shown correctly.

In my case I didn't need a function to change the order, and just change the order to the parameters in the function.

Thank you very much mledoze for the repository.

Don't worry for the delay, it happened to me many times.

Thank you for your comment, I appreciate it.