Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Tuesday, April 12, 2016

Protected areas

Though not really connected to the administrative subdivisions, I also keep following the changes in the protected areas - National Parks, Wildlife Sanctuaries and so on - when these are published in the Royal Gazette, and also created a XML schema to have the data on these in a machine readable format. In the last two weeks there were three announcements around these protected areas.
  • Creation of Non-hunting area Khao Phu Luang (เขตห้ามล่าสัตว์ป่าเขาภูหลวง) in Nakhon Ratchasima [Gazette], covering 232 km² of the forested hills around Lam Phra Loeng reservoir.
  • Remove of about 0.5 km² of Bakdai subdistrict out of the area of the Huai Thap Than - Huai Samran wildlife sanctuary (เขตรักษาพันธุ์สัตว์ป่าห้วยทับทัน-ห้วยสำราญ).
  • Declaration of Khao Khao (เขตที่ดินโบราณสถานเขาขาว) as a historical monument, protecting rock pantings on three hills in Ao Luek district, Krabi.
Especially for the third one, I even had expanded the XSD to be able to be able to encode the fact that this historical monument covers three separate areas with five specifically marked locations.

And while I was at it, I finally also found an Excel sheet with all the protected areas managed by the Department of National Park, Wildlife and Plant Conservation, most interestingly showing the internal codes used for these parks. Each of the class of protected areas has a number range, and is named in order of the creation of the park - but even though there is this simple numbering schema, the actual codes have been reworked twice already. The number ranges are
  • 1xxx for 127 National Parks (อุทยานแห่งชาติ)
  • 2xxx for 58 Wildlife Sanctuaries (เขตรักษาพันธุ์สัตว์ป่า)
  • 3xxx for 67 Non-hunting areas (เขตห้ามล่าสัตว์ป่า)
  • 4xxx for 110 Forest Parks (วนอุทยาน)
  • 9xxx for areas about to be protected - 20 National Parks, 2 Wildlife Sanctuaries and 3 Non-Hunting areas.
Dating from 2013, this sheet however does not include the above mentioned Khao Phu Luang Non-hunting area, though it seems none of the pending protected areas have been officially announced yet. Using that Excel sheet, I have now resumed work on the protected area XMLs, the one on the Forest Parks already has the complete list with creation date, area and the link to WikiData when available, only need to add the locations. However, the list which would be most useful for Wikipedia to support the annual "Wiki loves monuments" event is also the one which creates most work, as there are thousands of sites.

Tuesday, December 23, 2014

Milestones achieved

Right on time with the Christmas holidays and the New Year around the corner, I finally finished three major milestones in my data collection - the work which kept me busy the last months and ate away the time I normally used to write postings here. Each of the milestones would be worth a blog posting on its own, but as the final posting of this year I give a short overview of what was completed recently. A big thank you to my co-worker, without his contributions I would be still another two months short of completing these tasks.
  • For each of the local administrative units, the subdistricts which are covered by them completely or partially are now listed in the XML files. The penultimate statistics I published a month ago, when there were still about 1200 of 7700 entities still missing.
  • Now all the administrative villages are in the province XMLs as well. The latest official number of Muban I have is 74956 for 2012, but in the XMLs I have 75202 Muban - the excess 200 are probably Muban which were declared obsolete because of being in town or city municipalities.
  • Last but not least, all of the Royal Gazette announcements defining the boundaries of the subdistricts are now processed and translated in one XML file. This was an important tool to complete the Muban list, both to notice mistakes due to missing Muban in my previous lists, as well as confirming odd Muban names or finding names not found elsewhere. Though not all Tambon had been listed in these announcements, and there were several odd mistakes in the announcements as well, these were and will be a good reference now they are much easier accessible.
One long-running task is almost done as well, collecting the dates of the local elections. Especially since the military junta stopped all local elections, I "only" have to catch up - though in fact most of those missing in my data are those which are not published on any provincial Election Commission website, so it needs much more time for searching than the actual data editing.

But there are still more than enough further tasks I plan to do with the XMLs. Adding the locations of the administrative buildings, this will then help to add geographical data to the Wikipedia/Wikidata entries. And I just recently started to encode the neighboring entities into the XML files as well, something I should write in more details into a separate posting.

I wish all my readers happy holidays and good new year, no longer neglecting this blog like I did the last months is one of my New Years resolutions.

Thursday, July 3, 2014

Local governments and Tambon

On the German Wikipedia, there was recently a little discussion on how to better organized the administration section of the articles on the districts. Following the outline used on the English Wikipedia, first it listed the numbers of Tambon and Muban, then the local governments, and finally a table listing all the Tambon in the district. The Thai Wikipedia separates the two classes of subdivisions, it moves all the information on the local governments into a separate subsection. It seems that I am to blame for the original outline in the English Wikipedia, though I cannot remember exactly I think this was caused by the fact that I didn't know much about the local governments when starting the the districts, and only later started to add the local governments into the text of the administration section. Now the two German Wikipedians doing a lot of the work for articles around Thailand are migrating the articles into the new format, but having to work on nearly 900 articles will obviously take quite some time.

Since the local governments aren't always straight-forward one Tambon one local government - the municipalities existing before the year 2000 usually covered only parts of a Tambon, thus there are TAO which have to share the area of a Tambon with a municipality. On the other hand, there are TAO which have responsibility over more than one adjoining Tambon - especially in 2004 several smaller TAO were merged together, as well as the remaining Tambon Councils were merged into already existing TAO. Which Tambon is covered by which local government can be found in the Thai Wikipedia articles, but that's of course not easy to read for most non-Thai. I was asked whether I can supply a list of the TAO which are not responsible for exactly one Tambon, but sadly I did not have this information at hand.

I have now added some more optional data into my XML, defining a structure in the XSD to allow to add a list of Tambon covered by a local government together with the information whether it is a complete or a partial coverage. Without any special reason - I was just adding the Wikidata links to the Tambon there - I picked Mae Phrik district of Lampang province, where the newly added lines in the XML look like the following.

  <entity type="Amphoe" name="แม่พริก" english="Mae Phrik" geocode="5209"> 
    <entity type="Tambon" name="แม่พริก" english="Mae Phrik" geocode="520901">
      <office type="TAOOffice">
        <areacoverage>
          <entity geocode="520901" coverage="partially" />
          <entity geocode="520902" coverage="completely" />
        </areacoverage>
      </office>
    </entity>
    <entity type="Tambon" name="ผาปัง" english="Pha Pang" geocode="520902" />
    <entity type="Tambon" name="แม่ปุ" english="Mae Pu" geocode="520903" />
    <entity type="Tambon" name="พระบาทวังตวง" english="Phra Bat Wang Tuang" geocode="520904">
       <office type="MunicipalityOffice">
        <areacoverage>
          <entity geocode="520904" coverage="completely" />
        </areacoverage>
      </office> 
    </entity>
  </entity> 
  <entity type="ThesabanTambon" name="แม่ปุ" english="Mae Pu" geocode="5288" parent="5209">
    <office type="MunicipalityOffice">
      <areacoverage>
        <entity geocode="520903" coverage="completely" />
      </areacoverage>
    </office>
  </entity>
  <entity type="ThesabanTambon" name="แม่พริก" english="Mae Phrik" geocode="5287" parent="5209">
    <office type="MunicipalityOffice">
      <areacoverage>
        <entity geocode="520901" coverage="partially" />
      </areacoverage>
    </office>
  </entity>
 
With 7775 local governments (not counting the PAO as for those the area of coverage is obvious), I won't be able to fill this information to all any time soon, so this is yet another data item prepared and filled on demand, and it could be a nice task for any potential contributor to my XML to add this data more systematically. While the XML look quite technical, especially for anyone who has a bit of background in programming it should be very easy to contribute to them. Having the data structure defined, I guess my next step should be to add some code using this data to help Wikipedia editors...

Monday, April 22, 2013

Local elections this year

Two months ago I completed the election data for the years 2009 to 2012, so that for every local government unit I already had at least one council term in my XML files. Two months later, I now finished another year, the elections taking place in 2009 and thus ending this year - another 3722 data points. I have already started the final complete list I found at the Election Commission with the elections which took place in 2004 and ending their term in 2008 - thus most of those which had their latest election last year. Those are another 3135 data points, but working through those may be a bit faster since back in 2008 there much less local administrations which had their mayor and council term out of sync.

I also found a source for the official election endorsements at the Election Commission, many PDF files which list the winning mayor and council candidates, both for the main election as well as for by-elections. Though only maybe half of the provinces are found in that collection, and it also just goes back till the spring of 2012, it also made it possible to add a lot of data to the XMLs.

Those sources combined made it possible to notice that the yearly tables for the Election Commission cannot be trusted fully - especially for the council sizes there are changes which cannot be explained. It seems that in the older table for several TAO simply the number of Muban in the Tambon was used to calculate the council size, ignoring the fact that some of the Muban may be completely within a municipality and thus not eligible to elect councilors to the TAO. But since Muban can also be shared between municipality and TAO, it may even be possible that the Muban area under jurisdiction of the TAO has no citizen. I now have 65 cases where the council seemed to have changed, but I could no verify whether it really changed or one of the numbers is simply wrong.

Finally, thanks to the online archive of the +Phuket Gazette, I was able to reconstruct the election history for this one province since the turn of the century, including the very interesting case of Pa Tong municipality which had three election within few months - the first and second election after its upgrade to a town in 2002 were nulled due to election fraud.

I have to hurry to work through the 2008 data, because soon the municipal upgrades will begin - with around 3249 TAO having either (or both) a mayor or council term end this year, several will get upgraded to municipalities. So far only few upgrades were decided and documented in the board meeting transcripts, but to be effective in September when most of the terms end I soon have to focus on those as well.

Wednesday, February 27, 2013

Changing TAO council sizes

The size of the council of a subdistrict administrative organization (TAO) varies a lot, because every administrative village within the TAO has two elected councilors. Only in case there are less than three villages, the number of councilors per Muban is higher since the minimum size of the council is six. Thus there are TAO councils between six and more than 50 members. But not only the size of each TAO council differs, also the size of one TAO council can change - whenever a new administrative village is created, the council will be enlarged by two seats. The councilors from the village which is split are assigned to that part village in which they live, so its no necessarily the seats from the new village which will be filled in the by-election.

Now I add the council term ends in this year and thus the election dates for 2009, I stumble over several cases where the council size has changed between the 2005 and 2009 election. In those cases where I know that a new village was created during the term that change is easily explained - one example can be the TAO Chae Chang (องค์การบริหารส่วนตำบลแช่ช้าง) in San Kamphaeng district of Chiang Main province. In 2005 the council had 14 members, in 2009 it had 16 members. Today, the subdistrict contains 10 administrative villages - thus at first one would expect 20 TAO members. But village 7 is completely covered by the municipality San Kamphaeng and thus is not eligible to send councilors to the TAO council, and for village 8 the area which belongs to the TAO is unpopulated, only for Mu 6 one part of the population belongs to the municipality and another to the TAO - so effectively there are eight Muban for the TAO. And since village 10 was created in 2006 there must have been a by-election to enlarge the council shortly after the new Muban became effective.

This way I could already explain a big number of the council size changes, but sadly no all. Even though those files from where I copy my data are published by the Election Commission, they obviously contain wrong data - for example for the TAO Don Du (องค์การบริหารส่วนตำบลดอนดู่) in Khon Kaen province, according to the EC tables the council had a size of 18 in 2005 and 24 in 2009. But - the subdistrict has 12 villages and no area shared with any municipality, and already in 2002 it had 11 villages. Only one village was added in 2006, so the number for 2005 must have been 22, not 18. There were even a few cases where instead of the number of seats the table showed the number of constituencies (i.e. of Muban). In other cases, there were smaller councils in 2005, and in 2009 the council had two members for every Muban - but part of the subdistrict belongs to a municipality, and there were no boundary changes between TAO and municipality as far as I knew. So I have no idea why those Muban were eligible to have councilors in 2009, but not in 2005.

Apparently, the Excel sheets and PDFs from the ECT were created manually, otherwise such obvious mistakes could not happen. If I could spend more time on the programming part of my data collection project, I would easily have a small tool which could output the same tables from my collected data. But then there's still the problem that I don't have the full source data, I can only reconstruct them from those files I have. Especially whenever a mayor or a council ends its term prematurely I would have to update the data in the XML directly - but I rarely find these information at the ECT provincial websites.

Thursday, December 20, 2012

Times between local elections

As I am now adding lots of local election details into my XML, it now becomes possible to do some automatic calculation of election statistics. Though I am far from having a full coverage of the local elections of the most recent past - right now I have 4775 council elections with at least the election date - a few quite interesting things show up.

At first, most of the local election take place on either Sunday (4244 or 89%) or Saturday (410 or 9%), but there were also election on every other weekday. But it gets more interesting when I have more than one election date for a given local council, as then it is possible to calculate the time between the end of term and the election of a new council. By law, after the end of term the next election has to take place within 45 days, however this can be extended by the Election Commission. This takes place especially when the constituencies of the election need to be changed, either because the size of the council has changed, or the population numbers within the constituencies have changed significantly.

The number of days without a council within the limited data I have so far differs from 31 days, e.g. for Chiang Mai municipality earlier this year, when it had the election on April 8, exactly one month after the term ended on March 8. Quite striking however is the longest time I have spotted so far, more than once year for Pho Sadet municipality in Nakhon Si Thammarat. The TAO Pho Sadet was upgraded to a municipality effective October 7 2011, the first day after the TAO council term had expired. However, the first election for the municipal council and municipal mayor took place on November 11 2012, more than one year after the upgrade. For whatever reason, it took so long to split the area of the subdistrict into two constituencies with roughly equal population, as the constituencies were officially announced on October 10 2012, just shortly before the election date.

Right now, the median value of interregnum lengths is 52 days, however this is mostly a selection effect since I have mostly the election data for TAO upgraded to Thesaban - as soon as I add more of the recent TAO elections the number will certainly go down. But since it such a big pile of data to work through, and only part of it as handy Excel sheets which I can convert to XML code easily. In order to show how the data is represented in the XML, below is the code for the Pho Sadet council elections, snipped to show only the most relevant parts.

<entity type="Tambon" name="โพธิ์เสด็จ" english="Pho Sadet" geocode="800118">
<office type="MunicipalityOffice">

[...]
<officials>
<official title="Mayor" name="เกรียงศักดิ์ ด่านคงรักษ์" begin="2012-11-11" beginreason="ElectedDirectly" />
<official title="TAOMayor" name="เกรียงศักดิ์ ด่านคงรักษ์" begin="2007-10-07" end="2011-10-06" beginreason="ElectedDirectly" endreason="EndOfTerm" /></officials>
<
council>
<term begin="2012-11-11" type="ThesabanTambon" size="12" comment="Constituencies took 1 year to finish" />
<term begin="2007-10-07" end="2011-10-06" type="TAO" size="18" />
</council>
</office>
[...]
</
entity>

Thursday, November 19, 2009

How to join my Google code project

In case you want to fully use the data on the administrative entities I collected in XML, or the programming I did around that, you can download the whole thing to your computer and compile it yourself - and if you like even work in either the code or the data and then commit your changes into the global repository, so I can use them as well. The easiest way to join is to do exactly like I work, though especially if you just want to work on the XML there are other options as well. And if you just want to edit in the XML files, you don't need to be a programmer, and that can even be done with a plain text editor or on computer without Microsoft Windows. If you want to take a look first, you can do that online as well - the most interesting parts are the Royal Gazette announcements roughly sorted by topic and the data on the administrative entities, one file per province.

So to have this on your computer, first you need to download two programs - Microsoft's Visual Studio Express C# Edition which is both a quite good XML editor, as well as obviously the compiler for the program code I created. The second one is TortoiseSVN, the software which handles the download of the code from the repository and optionally the upload of your changes.

Once you installed both, you need to download the data first. Open the Explorer, go to the folder My Documents\Visual Studio 2008\Projects and do a right click on the mouse. In the popup menu select "SVN Checkout"

To download the project anonymously, you have to use the URL
http://tambon.googlecode.com/svn/trunk/
You will then get all the files into the folder you just selected.

If you plan to submit changes into the repository as well, you'll need to download the project with the URL
http://tambon.googlecode.com/svn/trunk/
(note the https instead of the http), and then when prompted enter your Google user name and the password you find at this Google code page.

However to really submit changes you made, you also need to email me and give me your Google account name, as I have to manually add you to the list of project members.

To update your local files with those in the repository, open the popup menu on the project folder and choose "SVN update". If you have done any changes in the local files which you want to share, then you can choose "SVN Commit", choose the files you want to submit, enter a good comment on what you changes, and provided you have write access it will then be available to everyone.

Wednesday, October 28, 2009

Collection of administrative office locations

For some time already I have added the geographical locations of the administrative into the XML files of my Tambon coding project. Now I have programmed a simple conversion of these XMLs wit locations into a KML file used in Google Earth, so I can easily display all the coordinates I have collected already.

In the map below is always the current version, which at the time of writing includes
  • Province halls (blue marker), 65 out of 75
  • District offices (green marker), 591 out of 927 (including those in Bangkok)
  • PAO offices (red marker), 10 out of 75
  • TAO (white marker), 74 out of 2105
  • Municipalities (yellow marker), 99 out of 5671

View Larger Map
The placemarks right now have no contents except the coordinates, unlike the one from an earlier experiment where I embedded photos and Wikipedia links, but for now I have concentrated on the essential things.

Quite obviously the coordinates are for from complete - for the district offices I have locations for all and only omitted those where Google Earth has no hires data yet to verify the accurate location. But especially for the municipalities and TAO these are quite difficult to find - some are from WikiMapia, for Samut Prakan Richard Barrow collected a few, rarely the website of the local government unit has a decent map which allows the identification in Google Earth.

So I can only call everyone interested to help making this collection more complete. You can send me any addition or correction by email, or if you have a lot and don't mind the XML editing you can join in the coding project and edit the XML yourself.

Monday, May 26, 2008

Gazette announcement data in XML format

Over the last months I worked a lot on finding and cataloging the Royal Gazette announcements, especially adding the entities affected so I can then find all announcements relevant to a specific district or municipality. I also did some coding in C# to assist my works with the announcements, most notably the search for new announcements. So far I concentrated on the actual functions, the user interface is still very crude.

As a small example below is the XML code for the creation of the minor district Vibhavadi in Surat Thani.

<entry description="Creation of King Amphoe Vibhavadi" title="ประกาศกระทรวงมหาดไทย เรื่อง แบ่งเขตท้องที่อำเภอคีรีรัฐนิคม จังหวัดสุราษฎร์ธานี ตั้งเป็นกิ่งอำเภอวิภาวดี" volume="109" page="19" issue="53 ง ฉบับพิเศษ" uri="2535/D/053/19.PDF" publication="1992-04-22" effective="1992-04-01" sign="1992-03-13">
<create geocode="8419" type="KingAmphoe" parent="8408">
<reassign geocode="841901" oldgeocode="840804"/>
<reassign geocode="841902" oldgeocode="840805"/>
</create>
</entry>

It is rather self-explaining I think - the fields inside the "entry" tag describe the announcement, including the date of signature, publication and the date it becomes effective, the URL within the online database, and the citation information volume, issue and page. The child nodes describe what the announcement is about, the creation of a new King Amphoe, which is a subordinate of another district - using the geocode to identify it, which is easier to parse (and easier to type) than the name Khiritat Nikhom. And as part of this creation, two Tambon got reassigned and therefore changed their geocode.

Though I doubt there is anyone else similar crazy about the administrative subdivisions of Thailand, and also interested in programming or at least XML editing, I have uploaded the whole data and code into an open source project at Google code, which offers a project hosting including a version control system. But in case anyone is interested, just look at the Tambon project, any help, comments or ideas are welcome.

Thursday, December 20, 2007

List of districts in 1917

I have found a very helpful entry in the Royal Gazette database - volume 34, pages 40 to 68 issued on April 29 1917. Innocently titled "ประกาศกระทรวงมหาดไทย เรื่อง เปลี่ยนชื่ออำเภอ" (Royal Order about rename of districts), this announcement not just list some name changes, but also includes all the districts which don't change their name at that time, thus it is a complete list of all the districts at that time. Sadly the monthon Krung Thep is missing, which at that time was under the control of the Ministry of Urban Affairs, and not the Interior Ministry as the others. But at least for some of the provinces abolished in 1932 I now know their territorial extend.

This announcement comes right at the end of the thesaphiban administrative reforms, as Prince Damrong resigned from his post as minister of Interior just two years earlier. With this announcement quite a lot of districts got renamed, some of the capital districts which were previously just named "Mueang" got the name of the province appended and thus already got the name they still have today. Other capital districts were renamed to have the same name as the subdistrict (tambon) which contains the district administration - which was also the main type of renamings done with this announcement. However in many cases the districts got back their historical name by the end of the 1930s.

Another thing covered by this announcement was the official change to use the term changwat (จังหวัด) for the provinces, which previously were still known as Mueang (เมือง).

I have converted the data of the announcement into a XML, which can be downloaded here. There are a few special cases where I am not fully sure about the identification of the district in the past with the modern-day one, but these are of course marked with comments within the file.

Wednesday, November 7, 2007

District data to XML

I am right now at the Microsoft TechEd in Barcelona, mostly for learning about the new technologies for my job as a programmer. But hearing loads of talk about useful new things around XML, and because I haven't yet had the time to learn much about how to create and use XML so far, the idea of converting the spreadsheet collecting the data into a set of XMLs. Apart from learning XML in much more details than before, it will also allow me to collect data which does not fit into the simple spreadsheet type, and also create small tools querying the XMLs, e.g. to find all the territorial changes related with one district - minor districts split off, single subdistricts getting reassigned and so on. Right now I think the first thing to do is to collect all those Royal Gazette references into one list, saving what they are about, which entities affected... Then the first bigger task would be convert the small application I created to parse the population data websites of DOPA and convert them into the tambon tables in the Wikipedia articles to actually use a much smarter data structure, both for saving the data as well as internally.