Announcement

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

  • Overlapping maps from two different coordinate datasets.

    I have constructed two maps of Nepal both attached below. One reflects 7 provinces while the other reflects 75 districts with 16 of my target districts labelled. Does anyone know how to overlap both these maps so that I have one map with all the districts as well as the province lines? I can share my do-files if needed.
    Attached Files

  • #2
    Here is an example of country boarders plotted in regional boarders:
    https://www.statalist.org/forums/for...92#post1530992

    Comment


    • #3
      Scott Merryman Thank you but I am still a little confused as to what manipulation you did within the Shapefile datasets. Do you thin you could explain your code a little further and what the polygon command is doing? Thanks a lot!

      Comment


      • #4
        The polygon() option allows you add an additional layer.

        Using the shapefiles located at: https://gadm.org/data.html

        Code:
        spshape2dta  gadm36_npl_2, replace
        spshape2dta  gadm36_npl_3, replace
        
        use gadm36_npl_3.dta   
         
        spmap using   gadm36_npl_3_shp.dta, id(_ID)  /// 
         ocolor(blue ) op(dot) ///
         polygon(data(gadm36_npl_2_shp) osize(vthin))
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	109.7 KB
ID:	1553632

        Comment


        • #5
          Scott Merryman Thank you very much this was very helpful. However, I would greatly appreciate it if you could help me with one more thing.

          I need to now label the 16 districts that I had labelled in the very first graph I attached, as well as label the 14 administrative zones that you have overlapped. The variable for the zones is "NAME_2". The district variable is "NAME_3" and the "_ID" values for the 16 districts are: 4,6,14,16,18,22,28,34,40,47,52,59,60,66,70,72. I tried creating separate data-sets with labels but the syntax does not seem to work when I use the polygon command. Do you think you could please help with this?

          Comment


          • #6
            Scott Merryman To be more precise this is the graph I was able to create using your code of combining the administrative zones and districts. However, I am not being able to add the labels of the zones which was the data used in the polygon command. Would you know how to incorporate that?
            Attached Files

            Comment


            • #7
              The -by()- suboption in the -polygon()- and -label()- options allow you to add multiple layers and labels. Using the same shapefiles, one needs to append the centroids and names of the administrative areas to district names and centroids and create an indicator variable to distinguish the layers.

              Code:
              clear
              //Country border layer
              use gadm36_npl_0_shp
              gen tag = 0
              //Add administrative area layer
              append using gadm36_npl_2_shp
              replace tag = 1 if tag == .
              save layer_0_2,replace
              
              //Centroids and names of administrative areas
              use gadm36_npl_2.dta ,clear
              keep NAME_2 _CX _CY
              rename NAME_2 NAME_3
              gen tag = 1
              
              //add district centroids and names 
              append using  gadm36_npl_3.dta
              //Name specific districts
              replace tag = 0 if inlist(NAME_3, "Achham" , "Parsa", "Morang")
              
              //Identify district to color
              gen foo = 1 if  inlist(NAME_3, "Achham" , "Parsa", "Morang")
              replace foo = 0 if foo == .
              
              spmap foo using  gadm36_npl_3_shp.dta, fcolor( white blue%20) id(_ID)  /// 
               ocolor(blue ... ) op(dot ...) ///
               label(xcoord(_CX) ycoord(_CY) label(NAME_3) by(tag) size(*.8 *1.2)) /// 
               polygon(data(layer_0_2) by(tag) osize(thick vthin))
              Click image for larger version

Name:	Graph.png
Views:	1
Size:	126.6 KB
ID:	1553797

              Comment


              • #8
                Scott Merryman Thank you so very much. This was immensely helpful!

                Comment


                • #9
                  Hi Scott, I'm using the polygon optoin, but two graphs don't overlay. Could you kidnly advise what's wrong here, please? Here's the command I used for the EU:

                  use "NUTS_RG_20M_2021_3035.dta", clear

                  merge 1:1 NUTS_ID using "data_for_NUTS3.dta"
                  keep if _m == 3
                  drop _m

                  * Polygon
                  spmap Var1 using NUTS_RG_20M_2021_3035_shp, id(_ID) fcolor(Blues2) clnumber(4) polygon(data(nuts2coord_Germany.dta) ocolor(black))


                  Many thanks!
                  Best wishes,
                  Meng Song
                  Attached Files

                  Comment

                  Working...
                  X