Read and show Mapinfo file in Streamlit

Example:

zip file content:

Code:

import streamlit as st
from geopandas import gpd
import os
import numpy as np
from numpy import *
import folium
import pygeoj
import leafmap.foliumap as leafmap
from streamlit_folium import folium_static

st.set_page_config(layout="wide")

file = st.file_uploader("请上传文件", type=["zip"])
if file is not None:
	head, sep, tail = str(file.name).partition(".")
	if tail == "zip":
		a = gpd.read_file(file, driver="Mapinfo File")
		b = a["geometry"]
		#st.write(b.area)显示TAB面积
		b.to_file('series.geojson', driver='GeoJSON')

		testfile = pygeoj.load("series.geojson")

		lon = []
		lat = []

		for feature in testfile:
			for i in range(len(feature.geometry.coordinates[0])):
				lon.append(feature.geometry.coordinates[0][i][0])
				lat.append(feature.geometry.coordinates[0][i][1])

		

		col1, col2, col3, col4, col5 = st.columns([0.05,1,0.2,0.8,0.45])
		with col1:
			st.empty()
		with col2:
			basemaps = {
			    'Esri Satellite': folium.TileLayer(
			        tiles = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
			        attr = 'Esri',
			        name = 'Esri Satellite',
			        overlay = True,
			        control = True
			    )
			}
			my_map = leafmap.Map(location=[mean(lat), mean(lon)], zoom_start=5)
			basemaps['Esri Satellite'].add_to(my_map)
			folium.GeoJson(open('series.geojson').read()).add_to(my_map)
			folium_static(my_map)
		with col3:
			st.empty()
		with col4:
			my_map = leafmap.Map(location=[mean(lat), mean(lon)], zoom_start=5)
			folium.GeoJson(open('series.geojson').read()).add_to(my_map)
			folium_static(my_map)
		with col5:
			st.empty()
1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.