前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >高质量编码-在线Excel经纬度坐标系转换(后台开发)

高质量编码-在线Excel经纬度坐标系转换(后台开发)

原创
作者头像
MiaoGIS
修改2021-07-15 11:12:27
5670
修改2021-07-15 11:12:27
举报
文章被收录于专栏:Python in AI-IOTPython in AI-IOT

后台核心代码使用GIS大神wandergis开源的coordtransform模块(Github链接https://github.com/wandergis/coordtransform

自己只是用Python web框架tornado做了一个web接口层,核心代码如下:

根据请求参数uid找到其上传的Excel文件,transform参数决定使用哪个转换函数,使用pandas处理Excel,简单高效。

代码语言:python
复制
from coordTransform.coordTransform_utils import *

def convert(row,convertFunc):
    lng=row['经度']
    lat=row['纬度']
    try:
        lng=float(lng)
        lat=float(lat)
        latlng=convertFunc(lng,lat)
        row['经度'],row['纬度']=latlng
    except:
        pass
    return row

 
dictTransform={'gcj02_to_bd09':gcj02_to_bd09,'bd09_to_gcj02':bd09_to_gcj02,
'wgs84_to_gcj02':wgs84_to_gcj02,'gcj02_to_wgs84':gcj02_to_wgs84,
 'bd09_to_wgs84':bd09_to_wgs84,'wgs84_to_bd09':wgs84_to_bd09,
 }

class coordTransformHandler(tornado.web.RequestHandler):
    def get(self):
        self.render('coordTransform.html')
    def post(self):
        uid=self.get_argument('uid')
        transform=self.get_argument('transform')
        xlsxPath=os.path.join('static/files/xlsx',uid+'.xlsx')
        xlsxPath2=os.path.join('static/files/xlsx',uid+'_convert.xlsx')
        transformFunc=dictTransform[transform]
        print(xlsxPath)
        if uid and os.path.exists(xlsxPath):
            df0=pd.read_excel(xlsxPath)
            df2=df0.apply(lambda x:convert(x,transformFunc),axis=1)
            df2.to_excel(xlsxPath2,index=False)
            self.write({'result':1})
            return 
        self.write({'result':0})

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档