API Docs for conflator¶
conflator.py¶
Bases: object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri |
str
|
URI for the primary database |
None
|
boundary |
str
|
Boundary to limit SQL queries |
None
|
Returns:
Type | Description |
---|---|
Conflator
|
An instance of this object |
Source code in osm_merge/conflator.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
|
getDistance ¶
getDistance(newdata, olddata)
Compute the distance between two features in meters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
newdata |
Feature
|
A feature from the external dataset |
required |
olddata |
Feature
|
A feature from the existing OSM dataset |
required |
Returns:
Type | Description |
---|---|
float
|
The distance between the two features |
Source code in osm_merge/conflator.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
|
checkTags ¶
checkTags(extfeat, osm)
Check tags between 2 features.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
extfeat |
Feature
|
The feature from the external dataset |
required |
osm |
Feature
|
The result of the SQL query |
required |
Returns:
Type | Description |
---|---|
int
|
The number of tag matches |
dict
|
The updated tags |
Source code in osm_merge/conflator.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
|
loadFile ¶
loadFile(osmfile)
Read a OSM XML file and convert it to GeoJson for consistency.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
osmfile |
str
|
The OSM XML file to load |
required |
Returns:
Type | Description |
---|---|
list
|
The entries in the OSM XML file |
Source code in osm_merge/conflator.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
|
initInputDB
async
¶
initInputDB(config=None, dburi=None)
When async, we can't initialize the async database connection, so it has to be done as an extrat step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dburi |
str
|
The database URI |
None
|
config |
str
|
The config file from the osm-rawdata project |
None
|
Returns: (bool): Whether it initialiized
Source code in osm_merge/conflator.py
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
|
initOutputDB
async
¶
initOutputDB(dburi=None)
When async, we can't initialize the async database connection, so it has to be done as an extrat step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dburi |
str
|
The database URI |
None
|
config |
str
|
The config file from the osm-rawdata project |
required |
Source code in osm_merge/conflator.py
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 |
|
createDBThreads
async
¶
createDBThreads(uri=None, config=None, execs=cores)
Create threads for writting to the primary datatbase to avoid problems with corrupting data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri |
str
|
URI for the primary database |
None
|
config |
str
|
The config file from the osm-rawdata project |
None
|
threads |
int
|
The number of threads to create |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the threads were created sucessfully |
Source code in osm_merge/conflator.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 |
|
conflateData
async
¶
conflateData(odkspec, osmspec, threshold=3.0)
Open the two source files and contlate them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
odkspec |
str
|
The external data uri |
required |
osmspec |
str
|
The existing OSM data uri |
required |
threshold |
float
|
Threshold for distance calculations in meters |
3.0
|
Returns:
Type | Description |
---|---|
list
|
The conflated output |
Source code in osm_merge/conflator.py
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 |
|
dump ¶
dump()
Dump internal data for debugging.
Source code in osm_merge/conflator.py
786 787 788 789 790 791 |
|
parseFile ¶
parseFile(filespec)
Parse the input file based on it's format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filespec |
str
|
The file to parse |
required |
Returns:
Type | Description |
---|---|
list
|
The parsed data from the file |
Source code in osm_merge/conflator.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 |
|
conflateDB ¶
conflateDB(source)
Conflate all the data. This the primary interfacte for conflation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
str
|
The source file to conflate |
required |
Returns:
Type | Description |
---|---|
dict
|
The conflated features |
Source code in osm_merge/conflator.py
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 |
|
writeOSM ¶
writeOSM(data, filespec)
Write the data to an OSM XML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
list
|
The list of GeoJson features |
required |
filespec |
str
|
The output file name |
required |
Source code in osm_merge/conflator.py
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 |
|
writeGeoJson ¶
writeGeoJson(data, filespec)
Write the data to a GeoJson file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
dict
|
The list of GeoJson features |
required |
filespec |
str
|
The output file name |
required |
Source code in osm_merge/conflator.py
960 961 962 963 964 965 966 967 968 969 970 971 972 973 |
|
osmToFeature ¶
osmToFeature(osm)
Convert an entry from an OSM XML file with attrs and tags into a GeoJson Feature.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
osm |
dict
|
The OSM entry |
required |
Returns:
Type | Description |
---|---|
Feature
|
A GeoJson feature |
Source code in osm_merge/conflator.py
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 |
|
options: show_source: false heading_level: 3
conflateBuildings.py¶
Bases: object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dburi |
str
|
The DB URI |
None
|
boundary |
Polygon
|
The AOI of the project |
None
|
Returns:
Type | Description |
---|---|
ConflateDB
|
An instance of this object |
Source code in osm_merge/conflateBuildings.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
addSourceFilter ¶
addSourceFilter(source)
Add to a list of suspect bad source datasets
Source code in osm_merge/conflateBuildings.py
66 67 68 69 70 71 |
|
overlapDB ¶
overlapDB(dburi)
Conflate buildings where all the data is in the same postgres database using the Underpass raw data schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dburi |
str
|
The URI for the existing OSM data |
required |
This is not fast for large areas!
Source code in osm_merge/conflateBuildings.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
cleanDuplicates ¶
cleanDuplicates()
Delete the entries from the duplicate building view.
Returns:
Type | Description |
---|---|
FeatureCollection
|
The entries from the datbase table |
Source code in osm_merge/conflateBuildings.py
114 115 116 117 118 119 120 121 122 123 124 |
|
getNew ¶
getNew()
Get only the new buildings
Returns:
Type | Description |
---|---|
FeatureCollection
|
The entries from the datbase table |
Source code in osm_merge/conflateBuildings.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
findHighway ¶
findHighway(feature)
Find the nearest highway to a feature
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature |
Feature
|
The feature to check against |
required |
Source code in osm_merge/conflateBuildings.py
145 146 147 148 149 150 151 152 153 154 |
|
getDuplicates ¶
getDuplicates()
Get the entries from the duplicate building view.
Returns:
Type | Description |
---|---|
FeatureCollection
|
The entries from the datbase table |
Source code in osm_merge/conflateBuildings.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
options: show_source: false heading_level: 3
conflatePOI.py¶
Bases: object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dburi |
str
|
The DB URI |
None
|
boundary |
Polygon
|
The AOI of the project |
None
|
threshold |
int
|
The distance in meters for distance calculations |
7
|
Returns:
Type | Description |
---|---|
ConflatePOI
|
An instance of this object |
Source code in osm_merge/conflatePOI.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
overlaps ¶
overlaps(feature)
Conflate a POI against all the features in a GeoJson file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature |
dict
|
The feature to conflate |
required |
Returns:
Type | Description |
---|---|
dict
|
The modified feature |
Source code in osm_merge/conflatePOI.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
queryToFeature ¶
queryToFeature(results)
Convert the results of an SQL to a GeoJson Feature
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results |
list
|
The results of the query |
required |
Returns:
Type | Description |
---|---|
list
|
a list of the features fromn the results |
Source code in osm_merge/conflatePOI.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
checkTags ¶
checkTags(feature, osm)
Check tags between 2 features.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature |
Feature
|
The feature from the external dataset |
required |
osm |
dict
|
The result of the SQL query |
required |
Returns:
Type | Description |
---|---|
int
|
The nunber of tag matches |
dict
|
The updated tags |
Source code in osm_merge/conflatePOI.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
conflateData ¶
conflateData(data, threshold=7)
Conflate all the data. This the primary interfacte for conflation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
list
|
A list of all the entries in the OSM XML input file |
required |
threshold |
int
|
The threshold for distance calculations |
7
|
Returns:
Type | Description |
---|---|
dict
|
The modified features |
Source code in osm_merge/conflatePOI.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
queryWays ¶
queryWays(feature, db=None)
Conflate a POI against all the ways in a postgres view
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature |
Feature
|
The feature to conflate |
required |
db |
GeoSupport
|
The datbase connection to use |
None
|
Returns:
Type | Description |
---|---|
list
|
The data with tags added from the conflation |
Source code in osm_merge/conflatePOI.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
|
queryNodes ¶
queryNodes(feature, db=None)
Find all the nodes in the view within a certain distance that are buildings or amenities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature |
Feature
|
The feature to use as the location |
required |
db |
GeoSupport
|
The database connection to use |
None
|
Returns:
Type | Description |
---|---|
list
|
The results of the conflation |
Source code in osm_merge/conflatePOI.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
options: show_source: false heading_level: 3
geosupport.py¶
Bases: object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dburi |
str
|
The database URI |
None
|
config |
str
|
The config file from the osm-rawdata project |
None
|
Returns:
Type | Description |
---|---|
GeoSupport
|
An instance of this object |
Source code in osm_merge/geosupport.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
importDataset
async
¶
importDataset(filespec)
Import a GeoJson file into a postgres database for conflation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filespec |
str
|
The GeoJson file to import |
required |
Returns:
Type | Description |
---|---|
bool
|
If the import was successful |
Source code in osm_merge/geosupport.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
initialize
async
¶
initialize(dburi=None, config=None)
When async, we can't initialize the async database connection, so it has to be done as an extrat step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dburi |
str
|
The database URI |
None
|
config |
str
|
The config file from the osm-rawdata project |
None
|
Source code in osm_merge/geosupport.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
clipDB
async
¶
clipDB(boundary, db=None, view='ways_view')
Clip a database table by a boundary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
boundary |
Polygon
|
The AOI of the project |
required |
db |
PostgresClient
|
A reference to the existing database connection |
None
|
view |
str
|
The name of the new view |
'ways_view'
|
Returns:
Type | Description |
---|---|
bool
|
If the region was clipped sucessfully |
Source code in osm_merge/geosupport.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
queryDB
async
¶
queryDB(sql=None, db=None)
Query a database table
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db |
PostgreClient
|
A reference to the existing database connection |
None
|
sql |
str
|
The SQL query to execute |
None
|
Returns:
Type | Description |
---|---|
list
|
The results of the query |
Source code in osm_merge/geosupport.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
clipFile
async
¶
clipFile(boundary, data)
Clip a database table by a boundary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
boundary |
Polygon
|
The filespec of the project AOI |
required |
data |
FeatureCollection
|
The data to clip |
required |
Returns:
Type | Description |
---|---|
FeatureCollection
|
The data within the boundary |
Source code in osm_merge/geosupport.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
copyTable
async
¶
copyTable(table, remote)
Use DBLINK to copy a table from the external database to a local table so conflating is much faster.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table |
str
|
The table to copy |
required |
Source code in osm_merge/geosupport.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
options: show_source: false heading_level: 3