├── LICENSE ├── provinces.sql ├── districts.sql └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Maduka Jayalath 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /provinces.sql: -------------------------------------------------------------------------------- 1 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 2 | 3 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 4 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 5 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 6 | /*!40101 SET NAMES utf8mb4 */; 7 | 8 | 9 | DROP TABLE IF EXISTS `provinces`; 10 | CREATE TABLE `provinces` ( 11 | `id` int NOT NULL, 12 | `name_en` varchar(45) NOT NULL, 13 | `name_si` varchar(45) DEFAULT NULL, 14 | `name_ta` varchar(45) DEFAULT NULL 15 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; 16 | 17 | INSERT INTO `provinces` (`id`, `name_en`, `name_si`, `name_ta`) VALUES 18 | (1, 'Western', 'බස්නාහිර', 'மேல்'), 19 | (2, 'Central', 'මධ්‍යම', 'மத்திய'), 20 | (3, 'Southern', 'දකුණු', 'தென்'), 21 | (4, 'North Western', 'වයඹ', 'வட மேல்'), 22 | (5, 'Sabaragamuwa', 'සබරගමුව', 'சபரகமுவ'), 23 | (6, 'Eastern', 'නැගෙනහිර', 'கிழக்கு'), 24 | (7, 'Uva', 'ඌව', 'ஊவா'), 25 | (8, 'North Central', 'උතුරු මැද', 'வட மத்திய'), 26 | (9, 'Northern', 'උතුරු', 'வட'); 27 | 28 | 29 | ALTER TABLE `provinces` 30 | ADD PRIMARY KEY (`id`); 31 | 32 | 33 | ALTER TABLE `provinces` 34 | MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10; 35 | 36 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 37 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 38 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 39 | -------------------------------------------------------------------------------- /districts.sql: -------------------------------------------------------------------------------- 1 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 2 | 3 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 4 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 5 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 6 | /*!40101 SET NAMES utf8mb4 */; 7 | 8 | 9 | DROP TABLE IF EXISTS `districts`; 10 | CREATE TABLE `districts` ( 11 | `id` int NOT NULL, 12 | `province_id` int NOT NULL, 13 | `name_en` varchar(45) DEFAULT NULL, 14 | `name_si` varchar(45) DEFAULT NULL, 15 | `name_ta` varchar(45) DEFAULT NULL 16 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; 17 | 18 | INSERT INTO `districts` (`id`, `province_id`, `name_en`, `name_si`, `name_ta`) VALUES 19 | (1, 6, 'Ampara', 'අම්පාර', 'அம்பாறை'), 20 | (2, 8, 'Anuradhapura', 'අනුරාධපුරය', 'அனுராதபுரம்'), 21 | (3, 7, 'Badulla', 'බදුල්ල', 'பதுளை'), 22 | (4, 6, 'Batticaloa', 'මඩකලපුව', 'மட்டக்களப்பு'), 23 | (5, 1, 'Colombo', 'කොළඹ', 'கொழும்பு'), 24 | (6, 3, 'Galle', 'ගාල්ල', 'காலி'), 25 | (7, 1, 'Gampaha', 'ගම්පහ', 'கம்பஹா'), 26 | (8, 3, 'Hambantota', 'හම්බන්තොට', 'அம்பாந்தோட்டை'), 27 | (9, 9, 'Jaffna', 'යාපනය', 'யாழ்ப்பாணம்'), 28 | (10, 1, 'Kalutara', 'කළුතර', 'களுத்துறை'), 29 | (11, 2, 'Kandy', 'මහනුවර', 'கண்டி'), 30 | (12, 5, 'Kegalle', 'කෑගල්ල', 'கேகாலை'), 31 | (13, 9, 'Kilinochchi', 'කිලිනොච්චිය', 'கிளிநொச்சி'), 32 | (14, 4, 'Kurunegala', 'කුරුණෑගල', 'குருணாகல்'), 33 | (15, 9, 'Mannar', 'මන්නාරම', 'மன்னார்'), 34 | (16, 2, 'Matale', 'මාතලේ', 'மாத்தளை'), 35 | (17, 3, 'Matara', 'මාතර', 'மாத்தறை'), 36 | (18, 7, 'Monaragala', 'මොණරාගල', 'மொணராகலை'), 37 | (19, 9, 'Mullaitivu', 'මුලතිව්', 'முல்லைத்தீவு'), 38 | (20, 2, 'Nuwara Eliya', 'නුවර එළිය', 'நுவரேலியா'), 39 | (21, 8, 'Polonnaruwa', 'පොළොන්නරුව', 'பொலன்னறுவை'), 40 | (22, 4, 'Puttalam', 'පුත්තලම', 'புத்தளம்'), 41 | (23, 5, 'Ratnapura', 'රත්නපුර', 'இரத்தினபுரி'), 42 | (24, 6, 'Trincomalee', 'ත්‍රිකුණාමලය', 'திருகோணமலை'), 43 | (25, 9, 'Vavuniya', 'වව්නියාව', 'வவுனியா'); 44 | 45 | 46 | ALTER TABLE `districts` 47 | ADD PRIMARY KEY (`id`), 48 | ADD KEY `provinces_id` (`province_id`); 49 | 50 | 51 | ALTER TABLE `districts` 52 | MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=26; 53 | 54 | 55 | ALTER TABLE `districts` 56 | ADD CONSTRAINT `fk_districts_provinces1` FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`); 57 | 58 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 59 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 60 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sri Lanka Provinces Districts Cities Database 2 | 3 | 4 | ### About 5 | 6 | This is a MySQL version of Sri Lankan Provinces => Districts => Cities, and related data. Each city has longitude, latitude, and postal code (postcode) other than its name. 7 | 8 | ### Data Errors 9 | If you discover wrong translations or any other issues, please use the issue tracker to mention or send a pull request with the changes. 10 | 11 | There are three SQL files, 12 | 1. provinces.sql (Names of nine provinces) 13 | 2. districts.sql (All districts related to each province) 14 | 3. cities.sql (All cities related to each district) 15 | 16 | 17 | ### Updates 18 | 19 | * July 18, 2016 - Changed the structure of cities table ability to add sub-city names. 20 | * April 25, 2022 - Completed translations in all three languages. 21 | 22 | 23 | ### Statistics 24 | 25 | * Provinces - 9 26 | * Districts - 25 27 | * Cities - 2154 28 | 29 | 30 | ### Sample tables structure with data 31 | 32 | **Provinces** 33 | 34 | | id | name_en | name_si | name_ta | 35 | | --- | ------- | -------- | ------- | 36 | | 1 | Western | බස්නාහිර | மேல | 37 | | 2 | Central | මධ්‍යම | மத்தி | 38 | 39 | 40 | **Districts** 41 | 42 | | id | province_id| name_en | name_si | name_ta | 43 | | --- | ---------- | ------------ | ------------ | ------------ | 44 | | 1 | 6 | Ampara | අම්පාර | அம்பாறை | 45 | | 2 | 8 | Anuradhapura | අනුරාධපුරය | அனுராதபுரம் | 46 | 47 | 48 | **Cities** 49 | 50 | | id | district_id | name_en | name_si | name_ta | sub_name_en | sub_name_si | sub_name_ta | postcode | latitude | longitude | 51 | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 52 | | 338 | 5 | Colombo 8 | කොළඹ 8 | கொழும்பு 8 | Borella | බොරැල්ල | பொறளை | 00800 | 6.914722 | 79.877778 | 53 | | 376 | 5 | Colombo 6 | කොළඹ 6 | கொழும்பு 6 | Wellawatta | වැල්ලවත්ත | வெள்ளவத்தை | 00600 | 6.874657 | 79.860483 | 54 | 55 | 56 | ### Installation 57 | 58 | To prevent unnecessary errors from occurring, start to import or execute provinces.sql, then districts.sql, and lastly cities.sql 59 | 60 | 61 | ### Usage 62 | 63 | **Advantages of latitude and longitude** 64 | 65 | * Integrate with Google Maps or any map-related service to show the exact place of the city on the map. 66 | * Find locations within a certain radius of a given latitude/longitude. 67 | 68 | **Find nearby locations using the Haversine formula** 69 | 70 | Here's the SQL statement that will find the closest locations within a radius of 25 kilometers to the 7.358849, 81.280133 coordinate. It calculates the distance based on the latitude/longitude of that row and the target latitude/longitude and then asks for only rows where the distance value is less than 25, ordering the whole query by distance. 71 | 72 | ```SQL 73 | SELECT id, name_en, name_si, name_ta, (6371 * ACOS(COS(RADIANS(7.358849)) * COS(RADIANS(latitude)) * COS(RADIANS(longitude) - RADIANS(81.280133)) + SIN(RADIANS(7.358849)) * SIN(RADIANS(latitude)))) AS distance 74 | FROM cities 75 | HAVING distance < 25 76 | ORDER BY distance 77 | ``` 78 | The above assumes that you have distance in kilometers. If distance is in miles then replace 6371 with 3959. 79 | 80 | References: 81 | 82 | * https://en.wikipedia.org/wiki/Haversine_formula 83 | * https://stackoverflow.com/questions/574691/mysql-great-circle-distance-haversine-formula 84 | 85 | ### Note 86 | 87 | * This free database does not guarantee the complete list of cities in Sri Lanka. 88 | * Feel free to contribute to the project. 89 | 90 | 91 | ### Translation status 92 | 93 | **Provinces** 94 | > 95 | > | සිංහල | தமிழ | 96 | > | ---- | ---- | 97 | > | 100% | 100% | 98 | 99 | **Districts** 100 | > 101 | > | සිංහල | தமிழ | 102 | > | ---- | ---- | 103 | > | 100% | 100% | 104 | 105 | **Cities** 106 | > 107 | > | සිංහල | தமிழ | 108 | > | ---- | ---- | 109 | > | 100% | 100% | 110 | 111 | --------------------------------------------------------------------------------