On Sun 2014-07-20 23:53:26, Pavel Machek wrote: > Ahoj! > > V priloze je skript na import zemedelske pudy z LPIS.
A ted ten skript. -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#!/usr/bin/python import shapefile from pyproj import * print "<?xml version='1.0' encoding='UTF-8'?>" print "<osm version='0.6' generator='pyshp'>" #p1 = Proj(init='my:2065') p1 = Proj(init='esri:102067') #p1 = Proj(init='EPSG:4326') p2 = Proj(init='EPSG:4326') sf = shapefile.Reader("PLPIS_223941_KU_KOD_631035") global field field = {} def a_field(num, name): global field i1, i2, i3, i4 = sf.fields[num] if name != i1: print 'Unexpected field name <', name field[name] = num a_field(1, 'ID_FB') a_field(3, 'NKODFB') a_field(6, 'PLATNYOD') a_field(7, 'VYMERAM') a_field(8, 'KULTURA') a_field(9, 'KULTURA_KL') a_field(10, 'KULTURAOD') a_field(11, 'EKO') a_field(21, 'VYSKA') a_field(22, 'SVAZITOST') a_field(26, 'KU_KOD') global nodeid nodeid = 0 def convert(point): lon, lat = point lon, lat = transform(p1, p2, lon, lat) return lon, lat def write_point(point): global nodeid lon, lat = convert(point) tags = '<tag k="created_by" v="shpupload"/>' tags += '<tag k="source" v="lpis"/>' nodeid -= 1 print '<node id="%d" lon="%f" lat="%f\">%s</node>' % ( nodeid, lon, lat, tags ) return nodeid def attr(shrec, name): return shrec.record[field[name]] for shrec in sf.shapeRecords(): shape = shrec.shape pts = [] for point in shape.points: pts += [ write_point(point) ] nodeid -= 1 print '<way id="%d">' % nodeid print ' <tag k="created_by" v="pyshp"/>' print ' <tag k="id_fb" v="%s"/>' % attr(shrec, 'ID_FB') print ' <tag k="source" v="lpis"/>' kul = attr(shrec, 'KULTURA') if kul == 2: print ' <tag k="landuse" v="farmland"/>' elif kul == 3: print ' <tag k="landuse" v="hop_field"/>' elif kul == 30: print ' <tag k="landuse" v="hop_field"/>' elif kul == 31: print ' <tag k="landuse" v="hop_field"/><tag k="crop" v="hop"/>' elif kul == 41: print ' <tag k="landuse" v="vineyard"/><tag k="barrier" v="fence"/>' elif kul == 61: print ' <tag k="landuse" v="orchard"/><tag k="barrier" v="fence"/>' elif kul == 62: print ' <tag k="landuse" v="orchard"/>' elif kul == 7: print ' <tag k="landuse" v="meadow"/>' elif kul == 71: print ' <tag k="landuse" v="meadow"/><tag k="barrier" v="fence"/>' elif kul == 72: print ' <tag k="landuse" v="meadow"/>' elif kul == 91: print ' <tag k="landuse" v="forest"/><tag k="barrier" v="fence"/>' elif kul == 92: print ' <tag k="landuse" v="farm"/><tag k="crop" v="vegetables"/>' elif kul == 97: print ' <tag k="landuse" v="reservoir"/>' elif kul == 98: print ' <tag k="landuse" v="forest"/><tag k="note" v="rychle rostouci dreviny"/>' elif kul == 99: print ' <tag k="landuse" v="forest"/>' else: print ' <tag k="landuse" v="unknown_farmland_%d"/>' % kul for pt in pts: print ' <nd ref="%d"/>' % pt print '</way>' print '</osm>'
_______________________________________________ Talk-cz mailing list Talk-cz@openstreetmap.org https://lists.openstreetmap.org/listinfo/talk-cz