Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Map Projections using Python's pyProj

    As an extension form this post: https://www.statalist.org/forums/for...-with-lat-long

    one can use Python's pyProj to create additional map projections that not available in Richard Picard's -geo2xy-.

    For example the Chamberlin trimetric projection or the Tobler-Mercator:

    Code:
    clear*
    
    //Note: spshape2dta cannot transform version 5.0
    copy "https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip?version=4.1.0" map.zip, replace
    unzipfile map.zip,replace
    spshape2dta ne_110m_admin_0_countries
    
    use ne_110m_admin_0_countries_shp
    
    //Tobler-Mercator
    //transformer = pyproj.Proj("+proj=tobmerc")
    python:
    from sfi import Data
    x = Data.get('_X')
    y  = Data.get('_Y')
    
    import pyproj
    #Chamberlin trimetric projection
    transformer = pyproj.Proj("+proj=chamb +lat_1=10 +lon_1=30 +lon_2=40")
    x1, y1 = transformer(x, y)
    x1, y1 = transformer(x, y)
    
    Data.addVarDouble("x1")
    Data.addVarDouble("y1")
    Data.store("x1", None, x1)
    Data.store("y1", None, y1)
    end
    
    replace x1 = . if _X ==.
    replace y1 = . if _Y == .
    drop _X _Y
    rename (y1 x1 ) (_Y _X)
    save ne_110m_admin_0_countries_shp2, replace
    
    use ne_110m_admin_0_countries
    colorpalette viridis, n(15) nograph
    local colors `r(p)'
    
    spmap GDP_MD using  ne_110m_admin_0_countries_shp2, id(_ID)  fcolor("`colors'") osize(0.04 ..) /// 
        cln(15) legend(off) name(map1,replace)
    Click image for larger version

Name:	map1a.png
Views:	1
Size:	205.8 KB
ID:	1654921



    Click image for larger version

Name:	map2.png
Views:	1
Size:	115.4 KB
ID:	1654922

  • #2
    Sounds like a Python and Stata problem

    Comment

    Working...
    X