def coord_conv(epsg_from,epsg_to,cord_xlong,cord_ylat): # if epsg_from and epsg_to : epsgfrom = SpatialReference() epsgfrom.ImportFromEPSG(epsg_from) epsgto = SpatialReference() epsgto.ImportFromEPSG(epsg_to) # Check for Projection exists if not epsgfrom.GetAttrValue("PROJCS|AUTHORITY", 1): cord_xlong=ddmmss_to_dd(cord_xlong) cord_ylat=ddmmss_to_dd(cord_ylat) psd2_IsProjected=False if epsgto.GetAttrValue("PROJCS|AUTHORITY", 1): psd2_IsProjected=True # Datum_epsg_from = epsgfrom.GetAttrValue("PROJCS|GEOGCS|AUTHORITY", 1) Datum_epsg_from = epsgfrom.GetAttrValue("GEOGCS|AUTHORITY", 1) Datum_epsg_to = epsgto.GetAttrValue("GEOGCS|AUTHORITY", 1) if int(Datum_epsg_from) == 4229: epsgfrom.SetTOWGS84(-121.8,98.1,-10.7,0,0,0.554,-0.2263) if int(Datum_epsg_to) == 4229: epsgto.SetTOWGS84(-121.8,98.1,-10.7,0,0,0.554,-0.2263) # ---------------------------- if psd2_IsProjected: FromTo_psd = CoordinateTransformation(epsgfrom, epsgto) x_to,y_to,zcart_to = FromTo_psd.TransformPoint(cord_xlong, cord_ylat) x_to = format(round(x_to,2),'.2f') y_to = format(round(y_to,2),'.2f') else: x_to,y_to,zcart_to=None,None,None # -------- Case Projected To Get the datum from info of epsg2 and calculate lat/long------------------------ epsgto.ImportFromEPSG(int(Datum_epsg_to)) if int(Datum_epsg_to) == 4229: epsgto.SetTOWGS84(-121.8,98.1,-10.7,0,0,0.554,-0.2263) FromTo_psd = CoordinateTransformation(epsgfrom, epsgto) long_to,lat_to,zcart2_to = FromTo_psd.TransformPoint(cord_xlong, cord_ylat) lat_to = ddmmss_to_dms(dd_to_ddmmss(lat_to)) + " N" long_to = ddmmss_to_dms(dd_to_ddmmss(long_to)) + " E" return (x_to,y_to,zcart_to,long_to,lat_to,zcart2_to)
def toWGS84(x, y): epsg28992 = SpatialReference() epsg28992.ImportFromEPSG(28992) epsg28992.SetTOWGS84(565.237, 50.0087, 465.658, -0.406857, 0.350733, -1.87035, 4.0812) epsg4326 = SpatialReference() epsg4326.ImportFromEPSG(4326) rd2latlon = CoordinateTransformation(epsg28992, epsg4326) latlon2rd = CoordinateTransformation(epsg4326, epsg28992) latlonz = rd2latlon.TransformPoint(x, y) return latlonz
def coord_conv(epsg_from, epsg_to, cord_xlong, cord_ylat): # if epsg_from and epsg_to: epsgfrom = SpatialReference() epsgfrom.ImportFromEPSG(epsg_from) if epsg_from != 4326: epsgfrom.SetTOWGS84(-121.8, 98.1, -10.7, 0, 0, 0.554, -0.2263) epsgto = SpatialReference() epsgto.ImportFromEPSG(epsg_to) if epsg_to != 4326: epsgto.SetTOWGS84(-121.8, 98.1, -10.7, 0, 0, 0.554, -0.2263) # ---------------------------- FromTo_psd = CoordinateTransformation(epsgfrom, epsgto) xlong, ylat, zcart = FromTo_psd.TransformPoint(cord_xlong, cord_ylat) # print(xlong,ylat,zcart) return (xlong, ylat, zcart)
def initcc(self): """ initialize coordinate conversion """ if not hasattr(self, 'rd2latlon'): from osgeo.osr import SpatialReference, CoordinateTransformation # Define the Rijksdriehoek projection system (EPSG 28992) epsg28992 = SpatialReference() epsg28992.ImportFromEPSG(28992) # correct the towgs84 epsg28992.SetTOWGS84(565.237, 50.0087, 465.658, -0.406857, 0.350733, -1.87035, 4.0812) # Define the wgs84 system (EPSG 4326) epsg4326 = SpatialReference() epsg4326.ImportFromEPSG(4326) self.rd2latlon = CoordinateTransformation(epsg28992, epsg4326)
def wgs84To28992(lo, la): # Define the Rijksdriehoek projection system (EPSG 28992) epsg28992 = SpatialReference() epsg28992.ImportFromEPSG(28992) # correct the towgs84 epsg28992.SetTOWGS84(565.237, 50.0087, 465.658, -0.406857, 0.350733, -1.87035, 4.0812) # Define the wgs84 system (EPSG 4326) epsg4326 = SpatialReference() epsg4326.ImportFromEPSG(4326) rd2latlon = CoordinateTransformation(epsg28992, epsg4326) latlon2rd = CoordinateTransformation(epsg4326, epsg28992) # Check the transformation for a point close to the centre of the projected grid xy = latlon2rd.TransformPoint(lo, la) return ([xy[0], xy[1]])
from osgeo.osr import SpatialReference, CoordinateTransformation # Define the Rijksdriehoek projection system (EPSG 28992) # EPSG:4326 WGS 84 # EPSG:4229 Egypt 1907 # EPSG:22992 Egypt 1907 / Red Belt # EPSG:22993 Egypt 1907 / Purple Belt # epsgRedBelt.SetTOWGS84(-121.8,98.1,-10.7,0,0,0.554,-0.2263) epsgPurpleBelt = SpatialReference() epsgPurpleBelt.ImportFromEPSG(22993) epsgPurpleBelt.SetTOWGS84(-121.8,98.1,-10.7,0,0,0.554,-0.2263) epsgRedBelt = SpatialReference() epsgRedBelt.ImportFromEPSG(22992) epsgRedBelt.SetTOWGS84(-121.8,98.1,-10.7,0,0,0.554,-0.2263) # correct the towgs84 # Egy 1907 7-par # Define the wgs84 system (EPSG 4326) epsgEgypt1907 = SpatialReference() epsgEgypt1907.ImportFromEPSG(4229) epsgEgypt1907.SetTOWGS84(-121.8,98.1,-10.7,0,0,0.554,-0.2263) epsgWgs84 = SpatialReference() epsgWgs84.ImportFromEPSG(4326) Red_WGS_latlon = CoordinateTransformation(epsgRedBelt, epsgWgs84) WGS_Red_latlon2rd = CoordinateTransformation(epsgWgs84, epsgRedBelt) pur_to_red = CoordinateTransformation(epsgPurpleBelt, epsgRedBelt)
def map_dataframe(dataframe, variable_string1, max_color, mid_color, popup_string1, save_string, variable_string2=None, popup_string2=None, variable_string3=None, popup_string3=None, variable_string4=None, popup_string4=None): """ Map dataframe function Maps the dataframe given as input to a folium map Saves the map in the assigned location :return: None """ with Session() as s: ## Load the location data in a pandas dataframe locationdata = parquet.readLocatie(s).toPandas() ## Used to convert coordinates from RDnew to WGS84 epsg28992 = SpatialReference() epsg28992.ImportFromEPSG(28992) epsg28992.SetTOWGS84(565.237, 50.0087, 465.658, -0.406857, 0.350733, -1.87035, 4.0812) epsg4326 = SpatialReference() epsg4326.ImportFromEPSG(4326) rd2latlon = CoordinateTransformation(epsg28992, epsg4326) ## Set center of map to center of Utrecht and create map SF_COORDINATES = (52.092876, 5.104480) map = folium.Map(location=SF_COORDINATES, zoom_start=14) ## Set a marker for each location in the dataframe for each in locationdata.iterrows(): for line in dataframe.collect(): if each[1]['MeetpuntRichtingCode'] == line['UniekeMeetpuntRichtingCode'] + '-1' or \ each[1]['MeetpuntRichtingCode'] == line['UniekeMeetpuntRichtingCode']: ## Select all coordinates which are not 'null' if each[1]['XRD'] != '': ## Convert coordinates X, Y, Z = rd2latlon.TransformPoint( int(each[1]['XRD']), int(each[1]['YRD'])) ## Create a marker for each location if variable_string4 != None: if line[variable_string1] > max_color or line[variable_string2] > max_color or \ line[variable_string3] > max_color or line[variable_string4] > max_color: color = 'red' elif line[variable_string1] > mid_color or line[variable_string2] > mid_color or \ line[variable_string3] > mid_color or line[variable_string4] > mid_color: color = 'orange' else: color = 'green' folium.Marker( location=[Y, X], popup=(folium.Popup( popup_string1 + ': ' + str(int(line[variable_string1])) + ', ' + popup_string2 + ': ' + str(int(line[variable_string2])) + ', ' + popup_string3 + ': ' + str(int(line[variable_string3])) + ', ' + popup_string4 + ': ' + str(int(line[variable_string4])), max_width=200)), icon=folium.Icon(color=color, icon='road')).add_to(map) elif variable_string3 != None: if line[variable_string1] > max_color or line[variable_string3] > max_color or \ line[variable_string4] > max_color: color = 'red' elif line[variable_string1] > mid_color or line[ variable_string2] > mid_color or line[ variable_string3] > mid_color: color = 'orange' else: color = 'green' folium.Marker( location=[Y, X], popup=(folium.Popup( popup_string1 + ': ' + str(int(line[variable_string1])) + ', ' + popup_string2 + ': ' + str(int(line[variable_string2])) + ', ' + popup_string3 + ': ' + str(int(line[variable_string3])), max_width=200)), icon=folium.Icon(color=color, icon='road')).add_to(map) elif variable_string2 != None: if line[variable_string1] > max_color or line[ variable_string2] > max_color: color = 'red' elif line[variable_string1] > mid_color or line[ variable_string2] > mid_color: color = 'orange' else: color = 'green' folium.Marker( location=[Y, X], popup=(folium.Popup( popup_string1 + ': ' + str(int(line[variable_string1])) + ', ' + popup_string2 + ': ' + str(int(line[variable_string2])), max_width=200)), icon=folium.Icon(color=color, icon='road')).add_to(map) else: if line[variable_string1] > max_color: color = 'red' elif line[variable_string1] > mid_color: color = 'orange' else: color = 'green' folium.Marker( location=[Y, X], popup=(popup_string1 + ': ' + str(int(line[variable_string1]))), icon=folium.Icon(color=color, icon='road')).add_to(map) ## Save the map to a .html file map.save(save_string)
#modelname='..\\modflowtest.nam' #mf = flopy.seawat.Seawat.load(modelname, exe_name='swt_v4') #coordinate transformations(RDnew, EPSG 28992): lon_1, lon_2 = (102000, 106000) lat_1, lat_2 = (507000, 506000) origin_x, origin_y = (101000, 505000) ur_x, ur_y = (107000, 510000) width = 50 dist = 50 ###Translate translation to WGS84(EPSG4326) # Define the Rijksdriehoek projection system (EPSG 28992) epsg28992 = SpatialReference() epsg28992.ImportFromEPSG(28992) # correct the towgs84 epsg28992.SetTOWGS84(565.237, 50.0087, 465.658, -0.406857, 0.350733, -1.87035, 4.0812) # Define the wgs84 system (EPSG 4326) epsg4326 = SpatialReference() epsg4326.ImportFromEPSG(4326) rd2latlon = CoordinateTransformation(epsg28992, epsg4326) latlon2rd = CoordinateTransformation(epsg4326, epsg28992) latlon1 = rd2latlon.TransformPoint(lon_1, lat_1) latlon2 = rd2latlon.TransformPoint(lon_2, lat_2) rasterLL = rd2latlon.TransformPoint(origin_x, origin_y) rasterUR = rd2latlon.TransformPoint(ur_x, ur_y) ###Large data formats (DIS, LPF, RCH, VDF) ###Bas bas_file = (r'modflowtest.bas') bas_data = pd.read_csv(bas_file, skiprows=3, delim_whitespace=True)