Skip to content

zimmaz/Convex-Layer-Depth-Locator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Country Convex Layer Depth Locator

A Class for finding the convex hull peeling depth of a given country by means of a recursive convex hull algorithm.

More on:

https://en.wikipedia.org/wiki/Convex_layers

Data set taken from:

https://www.kaggle.com/max-mind/world-cities-database

Get the country codes from:

https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

Example

    # Find the centroid town in Italy with a minimum population of 1000
    cc = CountryCentroid('world-cities-database.zip', cntry_id='it', min_pop=1000)
    # remove the outlier towns
    cc.remove_outliers_by_zscore()

After instantiation and removing the outlier points:

    # plot the towns on a scatter diagram
    cc.scatter_towns()
    plt.show()

Now we can plot the outer convex layer of Italy after finding the convex hull vertices:

    # find the convex vertices (first layer)
    cc.find_vertices()
    # plot
    cc.plot_convex_layer()
    plt.show()

    # peel the convex layers recursively
    cc.peel()
    # Show on 2d plot
    plt.show()
    # find the most populous town as the center of distribution
    print(cc.find_center_of_dist())

    Country            it
    City           arezzo
    AccentCity     Arezzo
    Region             16
    Population      95233
    Latitude      43.4167
    Longitude     11.8833
    X             22913.5
    Y              276608
    Name: 1504134, dtype: object

About

A class for finding the central tendency of a country

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages