Announcement

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

  • spmaps | How to overlay three (or more) polygons?

    Hi there, I would like to draw a map and then overlay it with two polygons (in my case the EU at NUTS3 level, at NUTS1 level and at member state level)

    The help file of spmaps suggests that overlaying multiple polygons is possible (it speaks of them in plural), but there is no example or instruction how to do that. When I code the following, I get the error option polygon() not allowed

    Code:
    spmap using NUTS3_shp, id(_ID) polygon(data(NUTS1_shp)) polygon(data(MEMBERSTATE_shp))
    I also played around with the syntax, of course, e.g. polygon(data(NUTS1_shp) data(MEMBERSTATE_shp))or polygon(data(NUTS1_shp MEMBERSTATE_shp)), but I couldn't get it working.

    Thank you for any advice!

  • #2
    You can accomplish this be -append-ing the polygon data sets together and using the by() option and drawn so that the lowest level is created first

    Code:
    cd "C:\Users\Scott\Desktop\temp1"
    spshape2dta  nuts_rg_01m_2016_3035_levl_3, replace
    
    use  nuts_rg_01m_2016_3035_levl_3.dta
    drop if _CX < 2100000
    drop if _CY <0
    save, replace
    
    //test
    spmap using  nuts_rg_01m_2016_3035_levl_3_shp, id(_ID) /// 
     ocolor(blue ) os(vthin) ///
     polygon(data(nuts_rg_01m_2016_3035_levl_0_shp) osize(thick)) /// 
     name(nuts0_3,replace)
    
     
    spshape2dta  nuts_rg_01m_2016_3035_levl_0, replace
    use  nuts_rg_01m_2016_3035_levl_0_shp,clear
    drop if _X <  2100000
    drop if _Y < 0
    gen nuts = 2
    save,replace
    
    // use nuts_rg_01m_2016_3035_levl_0.dta,clear
    // spmap using  nuts_rg_01m_2016_3035_levl_0_shp, id(_ID)
    
    spshape2dta  nuts_rg_01m_2016_3035_levl_1, replace
    use nuts_rg_01m_2016_3035_levl_1.dta,clear
    drop if _CX < 2000000
    save, replace
    
    use nuts_rg_01m_2016_3035_levl_1_shp
    drop if _X <  2100000
    drop if _Y < 0
    gen nuts = 1
    append using nuts_rg_01m_2016_3035_levl_0_shp
    save,replace
    
    use nuts_rg_01m_2016_3035_levl_3
    spmap using  nuts_rg_01m_2016_3035_levl_3_shp, id(_ID) /// 
     ocolor(blue ) os(vthin) ///
     polygon(data(nuts_rg_01m_2016_3035_levl_1_shp) by(nuts) /// 
     osize(medium medthick) ocolor(green black))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	181.9 KB
ID:	1531145
    :

    Comment


    • #3
      As in my other post (for later readers: https://www.statalist.org/forums/for...s-of-a-polygon) on this set of shapefiles: Thank you, Scott! Works perfectly. Now I also understand how one may use the by() option in spmaps.

      Comment

      Working...
      X