ThangLeQuoc / vietnamese-provinces-database

A complete SQL dataset of Vietnamese administrative units, includes Vietnamese provinces, districts and wards
MIT License
510 stars 169 forks source link

Include geographical data #56

Open ThangLeQuoc opened 4 months ago

ThangLeQuoc commented 4 months ago

Include geographical data Geographical data referenced from daohoangson/dvhcvn repository, his repository GIS resource is awesome. Don't hesitate to give his amazing repository a star as well

trungnam003 commented 3 months ago

Up

ThangLeQuoc commented 2 months ago

Feature is actively developed on branch integrate_gis_data, will ship it to the release soon Sneak peak:

image
ThangLeQuoc commented 1 month ago

When trying to check the validity of geom records, there are some records failed the check MySQL

SELECT *
FROM vn_gis vg 
WHERE ST_IsValid(gis_geom) IS FALSE;
image

The result is the same for Microsoft SQL Server, so we need to take time looking into the faulty geo record issue.

ThangLeQuoc commented 1 month ago

Using PostGis ST_IsValidReason reveal the following problem to the multipolygon

SELECT vn_gis.code, vn_gis."level", ST_IsValidReason(gis_geom)
FROM vn_gis
WHERE ST_IsValid(gis_geom) IS FALSE;
code level st_isvalidreason
184 district Ring Self-intersection[106.59603 21.99901]
617 district Self-intersection[108.001813 15.001936]
515 district Ring Self-intersection[108.001816 15.370833]
516 district Self-intersection[108.001813 15.002585]
511 district Self-intersection[108.001816 15.370833]
512 district Ring Self-intersection[108.001818 15.601409]
62 province Self-intersection[108.001813 15.001936]
645 district Self-intersection[108.001798 13.107198]
646 district Self-intersection[108.001798 13.106812]
639 district Ring Self-intersection[108.001801 13.600474]
660 district Ring Self-intersection[107.755919 11.998976]
661 district Self-intersection[107.755977 11.998976]
666 district Self-intersection[107.455934 11.998978]
667 district Self-intersection[107.455603 11.998978]
86 province Ring Self-intersection[106.074994 9.944899]

Validity rule of a Polygon

Some of the rules of polygon validity feel obvious, and others feel arbitrary (and in fact, are arbitrary).
- Polygon rings must close.
- Rings that define holes should be inside rings that define exterior boundaries.
- Rings may not self-intersect (they may neither touch nor cross themselves).
- Rings may not touch other rings, except at a point.
- Elements of multi-polygons may not touch each other.

Checking further, the self intersection look like this on the map

image

List of invalid geo_gis items:

SELECT *
FROM vn_gis vg 
WHERE code IN ('617','184','515','516','511','512','62','645','646','639','660','661','666','667','86');