forked from CowSmiles/regions-of-china
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
38,786 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This is the official list of regions-of-china authors for copyright purposes. | ||
# This file is distinct from the CONTRIBUTORS files. | ||
# See the latter for an explanation. | ||
|
||
# Names should be added to this file as | ||
# Name or Organization <email address> | ||
# The email address is not required for organizations. | ||
|
||
# Please keep the list sorted. | ||
|
||
Dong Liu <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This is the official list of people who can contribute | ||
# (and typically have contributed) code to the regions-of-china repository. | ||
# The AUTHORS file lists the copyright holders; this file | ||
# lists people. | ||
# | ||
# The submission process automatically checks to make sure | ||
# that people submitting code are listed in this file (by email address). | ||
|
||
# Names should be added to this file like so: | ||
# Name <email address> | ||
# | ||
# An entry with two email addresses specifies that the | ||
# first address should be used in the submit logs and | ||
# that the second address should be recognized as the | ||
# same person when interacting with Rietveld. | ||
|
||
# Please keep the list sorted. | ||
|
||
Dong Liu <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright (c) 2015 The regions-of-china Authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of Dong Liu <[email protected]>. nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
# regions-of-china | ||
The administrative divisions of China, privated sql, txt format data. | ||
# Regions of China | ||
The administrative divisions of China, provade CSV, SQL, text, Excel and XML data format. | ||
|
||
# Data format | ||
* regions-of-china.csv CSV format. | ||
* regions-of-china.sql SQL format. | ||
* regions-of-china.txt Text format. | ||
* regions-of-china.xlsx Excel format. | ||
* regions-of-china.xml XML format. | ||
|
||
# References | ||
* https://en.wikipedia.org/wiki/List_of_regions_of_the_People%27s_Republic_of_China | ||
* https://en.wikipedia.org/wiki/Administrative_divisions_of_China | ||
* https://en.wikipedia.org/wiki/Provinces_of_China | ||
* http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201504/t20150415_712722.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2015 The regions-of-china Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"log" | ||
"bufio" | ||
"os" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
fr, err := os.Open("regions-of-china.txt") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
defer fr.Close() | ||
|
||
fw, err := os.Create("regions-of-china.sql") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
defer fw.Close() | ||
|
||
provinceID := "0" | ||
provinceName := "" | ||
cityID := "0" | ||
cityName := "" | ||
queryTpl := "('%s', '%s', '%s', '%s', '%s', '%s')," | ||
|
||
scanner := bufio.NewScanner(fr) | ||
writer := bufio.NewWriter(fw) | ||
|
||
fmt.Fprintln(writer, "INSERT INTO region (`district_id`, `district_name`, `city_id`, `city_name`, `province_id`, `province_name`) VALUES") | ||
|
||
for scanner.Scan() { | ||
t := scanner.Text() | ||
if t[0] == '#' { | ||
continue | ||
} | ||
|
||
str := "" | ||
nodes := strings.Split(t, " ") | ||
switch len(nodes) { | ||
case 2: // Province | ||
provinceID = nodes[0] | ||
provinceName = nodes[1] | ||
str = fmt.Sprintf(queryTpl, "0", "", "0", "", provinceID, provinceName) | ||
case 3: // City | ||
cityID = nodes[0] | ||
cityName = nodes[2] | ||
str = fmt.Sprintf(queryTpl, "0", "", cityID, cityName, provinceID, provinceName) | ||
case 4: // District | ||
str = fmt.Sprintf(queryTpl, nodes[0], nodes[3], cityID, cityName, provinceID, provinceName) | ||
default: // Err | ||
fmt.Printf("$s\n", t) | ||
} | ||
|
||
fmt.Fprintln(writer, str) | ||
} | ||
|
||
writer.Flush() | ||
} |
Oops, something went wrong.