Add 'shp_2_txt.py'

This commit is contained in:
zwnk 2019-05-23 00:04:29 +02:00
parent efe71c0417
commit e86aaba613
1 changed files with 61 additions and 0 deletions

61
shp_2_txt.py Normal file
View File

@ -0,0 +1,61 @@
# Example Output for a complete record of MA.dbf:
# OrderedDict([('FeatureId', None), ('DATA_DATE', '20190402'), ('DATA_SRCE', 'http://www.ngs.noaa.gov/cgi-bin/ds_mark.prl?PidBox=DF6866'),
# ('PID', 'DF6866'), ('NAME', '204 S'), ('HT_MOD', ''), ('CORS_ID', ''), ('PACS_SACS', ''), ('STATE', 'MA'),
# ('COUNTY', 'PLYMOUTH'), ('QUAD', ''), ('LATITUDE', '41 48 42.93229(N)'), ('LONGITUDE', '070 57 49.32872(W)'),
# ('DEC_LAT', ' 41.8119256361'), ('DEC_LON', ' -70.9637024222'), ('ELLIP_HT', ''), ('POS_DATUM', 'NAD 83'), ('DATUM_TAG', '(1996)'),
# ('POS_EPOCH', ''), ('POS_SRCE', 'ADJUSTED'), ('ORTHO_HT', ' 18.5'), ('VERT_DATUM', 'NAVD 88'), ('VERT_EPOCH', ''), ('VERT_SRCE', 'VERTCON'),
# ('GEOID_HT', '-29.000'), ('GEOID_MOD', 'GEOID12B'), ('DYNAMIC_HT', ''), ('MODEL_GRAV', ''),
# ('N_ACC_HZ', ''), ('N_ACC_EH', ''), ('N_ACC_STDN', ''), ('N_ACC_STDE', ''), ('N_ACC_STDH', ''), ('N_ACC_CORR', ''),
# ('POS_ORDER', '2'), ('VERT_ORDER', ''), ('VERT_CLASS', ''), ('DIST_RATE', ''), ('ECEF_X', ''), ('ECEF_Y', ''), ('ECEF_Z', ''),
# ('SPC_ZONE', 'MA M'), ('SPC_NORTH', '840320.139'), ('SPC_EAST', '244562.406'), ('SPC_CONV', '+0 21 36.9'), ('SPC_CSF', '0.99998907'),
# ('UTM_ZONE', '19'), ('UTM_NORTH', '4630758.769'), ('UTM_EAST', '336889.228'), ('UTM_CONV', '-1 18 34.1'), ('UTM_CSF', '0.99992904'),
# ('STABILITY', 'C'), ('FIRST_RECV', '1972'), ('LAST_RECV', '1972'), ('LAST_COND', 'MONUMENTED'), ('LAST_RECBY', 'MAGS'), ('SAT_USE', ''),
# ('MARKER', 'DE = TRAVERSE STATION DISK'), ('SETTING', '7 = SET IN TOP OF CONCRETE MONUMENT'), ('STAMPING', '204 S')])
# dbfread 4 reading dbf files xD
# https://dbfread.readthedocs.io/en/latest/
from dbfread import DBF
dbf_file = DBF("f:\\testing\\shp_2_txt\\MA.dbf", load=True, encoding='utf8')
txt_file = open("f:\\testing\\shp_2_txt\\MA.txt", 'w')
for idx, record in enumerate(dbf_file):
txt_file.write(str(record['DEC_LON'] + record['DEC_LAT'] + record['ELLIP_HT'] + record['ORTHO_HT']) + '\n')
txt_file.close()
'''
example output:
-70.7394444444 42.1352777778 37.353
-70.6813444444 41.9707972222 17.272
-70.8055555556 41.8088888889 30.880
-72.6272222222 42.1002777778 25.081
-71.2006926306 42.2805601694 33.38
-71.2044365639 42.2842648639 37.48
-71.2113334333 42.2884181889 13.831 41.9
-71.2247152417 42.3027485556 37.45
-71.2264975000 42.3056014861 36.8
-71.2385133250 42.3199885083 24.26
-71.2461568361 42.3200455944 24.07
-71.2497087361 42.3239398472 24.6
-71.2523207583 42.3281380722 28.99
-71.2565808000 42.3349880611 32.99
-71.2628130389 42.3400665917 26.93
-71.2621557417 42.3465060750 23.48
-71.2643755028 42.3520566472 30.63
-71.2701964694 42.3581546139 44.59
-71.2698026389 42.3697727750 37.85
-73.2419444444 42.4533333333 306.684
-73.2419444444 42.4533333333 307.463
-73.2419444444 42.4533333333 307.552
-73.2636111111 42.4472222222 308.236
-71.8513239778 42.3631945833 226.
-71.8675337250 42.4016609306 271.
-72.6852777778 42.1083333333 39.843
-70.5438609000 41.7801187861 25.1
'''