Package: kvadratnet
Kvadratnet is a set of tools that makes working with the Danish
Kvadratnet easier.IntroductionThe Danish Kvadratnet is a geographical tiling scheme based on UTM
coordinates. The tiling scheme is a national standard for dividing
nation-wide geographical datasets into smaller pieces.The Danish Kvadratnet was originally created as a collaboration betweenStatistics Denmarkand theNational Survey and
Cadastre of Denmarkas a static administrative
geographical subdivision of the country. The reasoning behind this was
that usual administrative boundaries, such as municipal boundaries, are
known to change from time to time and are therefore not very suitable as
a geographical administrative index.The Danish Kvadratnet consist of a severalnetworksthat covers the
country with square tiles of varying sizes. Supported tile sizes are:
100m, 250m, 1km, 10km, 50km and 100km. Individual tiles are identified
by tile size and the coordinates of the lower left corner of a tile. The
coordinates are truncated accordinging to the size of the tile i.e.
1km_6452_523. Examples of tile identifiers can be seen in the table
below:NetworkTile name example100km100km_62_550km50km_620_5510km10km_622_571km1km_6223_576250m250m_622375_57550100m100m_62237_5756Use of the kvadratnet module is not limited to the geographical area of
Denmark. The tiling scheme can be applied to any region on earth as the
UTM coordinate system is defined worlwide. Care has to be taken in case
use of the tiling scheme spans more than one UTM zone, since coordinates
are duplicated across zones. This can be solved by keeping all data in
the same UTM zone, even though some of it might be placed outside the
zone. By using robust UTM coordinate transformation libraries, such as
the Extended Transverse Mercator implementation inproj.4, data can
be kept in the same coordinate system even though it spans several UTM
zones. This exact procedure is used by the Grenland Survey,Asiaq, which organizes data across 10 UTM
zones.ExampleExample of usingkvadratnetSuppose you have a range of files organized in the 1km network. We want
to count how many 1km tiles are present in each parent 10km tile.fromcollectionsimportCounterimportkvadratnetfiles=['dtm_1km_6121_867.tif','dtm_1km_6125_866.tif','dtm_1km_6125_862.tif','dtm_1km_6423_512.tif','dtm_1km_6253_234.tif','dtm_1km_6235_634.tif','dtm_1km_6424_513.tif','dtm_lkm_5223_523.tif','dtm_1km_6251_236.tif','dtm_1km_6424_517.tif']counter=Counter()forfilenameinfiles:try:name=kvadratnet.tile_name(filename)except:counter['bad_name']+=1parent=kvadratnet.parent_tile(name,'10km')counter[parent]+=1print(counter)# Counter({'10km_642_51': 4, '10km_612_86': 3, '10km_625_23': 2, '10km_623_63': 1, 'bad_name': 1})knet - command line interfacekvadratnetalso has a command line interface calledknet. Theknetcommand is a front for various tools that make life managing
files with kvadratnet naming a lot easier. For instance renaming many
files:# add a prefix before the cell identifier
$ knet rename --prefix PUNKTSKY_ "*.laz"

# strip anything but the cell identifier
$ knet rename PUNKTSKY*.lazWithknetorganizing files in subfolders according to which parent
tiles they belong to is easy:# divide files into 100km and 10km folders
$ knet organize "1km*.tif" 100km 10kmInstallationInstallation can be done either viapip install kvadratnetor by downloading the source code and runningpython setup.py installTestingnoseis used for testing. The test-suite can be invoked by runningnosetests -v