Announcement

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

  • Mapping the administrative divison (by delegations and municipalities) of the Tunisian Governorate of "Nabeul" using spmap and shapefiles

    Hello Stata Community;

    I'am working on the Tunisian Governorate of Nabeul, and I would love to draw a map showing its administrative divison by Delegations (16 delegation) and another map of the same Governorate, this time divised by Municipalities (28 municipality). I've tried looking for the shapefile for the task, but I couldn't find it.
    I would love to have both of the maps (one divised by Delegations, and the other by Municipalities), also, I would love to have the names of the Delegations and Municipalities written on the graphs (like, on the related region), still, I think it will get the graphs a bit "crowed" (especially for the Municipalities graph, as there are 28 of them), and it will be great if I could get the names in Arabic, if not, French or English will do.

    I really hope I could get some help.
    With many Thanks .

  • #2
    Your question is best answered by the GIS community, but this may be a place to start:

    https://data.humdata.org/dataset/cod-ab-tun?
    https://malouche.github.io/MapTunisiaWithR/index.html

    The second link points to shape files for Tunisian Delegations and Gouvernorats.

    Comment


    • #3
      Thanks for the help Daniel Shin Yet, I was looking for the GIS (or the Shaefile) of just one Governorate, which is Nabeul, and not the entire Tunisian country Yet, it will be very helpful if I could get the same shapefiles, but just for Nabeul.
      It is actually my first time using shapefiles, so I'm not that fluent with them It will be very helpful if I got get the full on code of mapping the Governorate by Delegations and Municipalities.
      Thanks

      Comment


      • #4
        Here's a quick guide: https://www.stata.com/support/faqs/g...pmap-and-maps/

        First, download the sph, spx and dbf files from https://github.com/malouche/Maps-of-Tunisia-Gouvernorat

        Then follow the commands for a basic plot of all gouvernorats. The guide should tell you how to plot using variables and such.

        Code:
        ssc install spmap
        ssc install shp2dta
        
        shp2dta using Tunisie_snuts3, database(tundb) coordinates(tuncoord) genid(ID)
        use tundb, clear
        spmap ID using tuncoord, id(ID)

        Comment


        • #5
          Daniel Shin Thanks for the help Your instructions seem to be the closest ones to my request, Thank you Tho the thing is, I jwant to draw just the map of Nabeul (which is a governorate or a district of Tunisia) and not the whole Tunisian country, so I don't know if it is possible to find sph, spx and dbf files for Nabeul with its delegations and municipalities division (administrative division), because that's my goal.
          Thanks again for the help.

          Comment


          • #6
            Daniel Shin I did find the shapefil for the region of Nabeul that I wanna work on, yet, when I tried to type the code you've shared, I get this message:

            (note: named style . not found in class numstyle, default attributes used)
            (note: named style 1 not found in class numstyle, default attributes used)
            invalid label specifier, : .:
            r(198);

            I kinda don't get what's wrong, I guess there's a problem with the "ID" variable, it's just a guess tho, so please let me share the code here:

            ssc install spmap
            ssc install shp2dta

            shp2dta using Délégation_Nabeul, database(nabdb) coordinates(nabcoord) genid(ID)
            type: 5

            . use nabdb, clear

            Yet, when I type the command: spmap ID using nabcoord, id(ID) I get that error message

            Please, any help ??
            I appreciate that already Thanks

            Comment


            • #7
              Could you share the link where you got the Nabeul shapefiles? Do you have any non-distinct labels in nabdb.dta?

              Comment


              • #8
                Daniel Shin So this is the link: https://brahimjaziri.jimdofree.com/b...%A9chargement/
                You just have to log on "Nabeul" and then download the .zip file.
                Really appreciate your help. Thanks

                Comment


                • #9
                  Ok, I have found an issue with shp2dta where if you do not generate centroids, the ID variables are generated inconsistently and therefore the database and the coordinate files do not correspond. The database files that are generated still look somewhat odd, and you may need to do some checking such as plotting by ID so you can be sure the IDs correspond to the correct map as labeled.

                  From the file link you posted, I generated three sets of maps, one at the gov, one at del, and one at sec level:

                  Code:
                  * Gouvernorat
                  shp2dta using "Gouvernorat Nabeul", database(gdb) coordinates(gcoord) genid(ID) gencentroids(centroid) replace
                  use gdb, clear
                  spmap using gcoord, id(ID) name(gov)
                  
                  * Delegation
                  shp2dta using "D‚l‚gation Nabeul", database(ddb) coordinates(dcoord) genid(ID) gencentroids(centroid) replace
                  use ddb, clear
                  spmap using dcoord, id(ID) name(del)
                  
                  * Sector
                  shp2dta using "Secteur Nabeul", database(sdb) coordinates(scoord) genid(ID) gencentroids(centroid) replace
                  use sdb, clear
                  spmap using scoord, id(ID) name(sec)
                  
                  graph combine gov del sec
                  Click image for larger version

Name:	Screenshot 2023-03-02 at 12.59.38 PM.png
Views:	1
Size:	496.9 KB
ID:	1704158

                  Comment


                  • #10
                    I should note, shp2dta is not part of base Stata. You may get more answers from the author (Kevin Crow at Stata, [email protected]).

                    Comment


                    • #11
                      Daniel Shin Thanks very much That's kinda what I wanna do.
                      Tho, just a follow-up question if I may, because I really want to understand this whole mapping procedure: About the names of the delegations (talking about the map of the delegations divison), is there an option in the codes to put in order to show the names of the delegations on the map (or on the side of each delegation with arrows), or should the shapefile be downloaded with a names files?? I want to show the names at least for the delegations map, I guess for the sectors if I do that, the map will get too crowded.
                      Thanks

                      Comment


                      • #12
                        This is something I haven't done before, but it should be doable. The map is basically plotted with a bunch of x and y coordinates, and since you have centroid elements (center of each mapping element), you should be able to overlay text. I will take a look and get back to you.

                        Comment


                        • #13
                          Much easier way (surprise, there is an option for this):

                          Code:
                          * Delegation
                          shp2dta using "D‚l‚gation Nabeul", database(ddb) coordinates(dcoord) genid(ID) gencentroids(centroid) replace
                          use ddb, clear
                          spmap using dcoord, id(ID) name(del)
                          replace alt_name_f=alt_name_f[_n+16] if _n<=16 // KEY
                          spmap using dcoord, id(ID) name(del_label) label(x(x_centroid) y(y_centroid) l(alt_name_f))
                          
                          graph combine del del_label
                          For some reason shp2da separates out the map elements and the metadata such you have to merge the names back into the correct mapping elements. I am making a major assumption that the database file generated keeps the mapping elements in order. The map "looks" correct in that Nabeul and Kelibia seem to be in the right place. Please check your data integrity rigorously.
                          Click image for larger version

Name:	Graph.png
Views:	2
Size:	288.1 KB
ID:	1704584
                          Attached Files

                          Comment


                          • #14
                            Daniel Shin I really do appreciate the help Thanks very much, it really worked.
                            Tho, just a follow-up final question please: About colors, is there an option to introduce in the code so that I could give a color for each delegation ?? Just to make the map more visually appealing please
                            I would so appreciate that if you could help Thanks

                            Comment


                            • #15
                              Yes, coloring is possible, but you would need to assign a value for each color and apply this color label to your dataset. In spmap, the coloring is to generally to illustrate data (e.g. levels of income, pollution, corruption, etc.). If you just want colors so that they are distinct, you're probably thinking about the four color theorem (you need minimum of 4 colors so no two elements sharing an edge have the same color). For a small map like this, you could map it yourself, or implement this programmatically. I don't think this is implemented in spmap.

                              The first example is using 4 colors for a quasi-cartographic figure (you will need to do this manually if you want map-quality). The second example uses a color gradient to show distinct delegations. Do look at help spmap for more options.

                              Code:
                              * Delegation
                              shp2dta using "D‚l‚gation Nabeul", database(ddb) coordinates(dcoord) genid(ID) gencentroids(centroid) replace
                              use ddb, clear
                              replace alt_name_f=alt_name_f[_n+16] if _n<=16
                              replace ref_tn_cod=ref_tn_cod[_n+16] if _n<=16
                              replace code_gouve=code_gouve[_n+16] if _n<=16
                              replace Nom_gouver=Nom_gouver[_n+16] if _n<=16
                              drop if _n>16
                              egen rank=rank(runiform())
                              gen class1=ceil(rank/_N*4)
                              gen class2=_n
                              
                              * 4 CLASSES
                              spmap class1 using dcoord, name(del_col1) id(ID) fcolor(Terrain) clmethod(unique) label(x(x_centroid) y(y_centroid) l(alt_name_f))
                              
                              * UNIQUE CLASSES
                              spmap class2 using dcoord, name(del_col2) id(ID) fcolor(Blues2) clmethod(unique) label(x(x_centroid) y(y_centroid) l(alt_name_f))
                              
                              graph combine del_col1 del_col2

                              Click image for larger version

Name:	Graph2.png
Views:	2
Size:	337.1 KB
ID:	1704731
                              Attached Files

                              Comment

                              Working...
                              X