首页 > 其他分享 >[969] Add a spatial reference (a coordinate reference system, CRS) to a GeoDataFrame in GeoPandas

[969] Add a spatial reference (a coordinate reference system, CRS) to a GeoDataFrame in GeoPandas

时间:2024-02-08 14:12:47浏览次数:19  
标签:CRS reference df GeoPandas system GeoDataFrame Latitude

To add a spatial reference (a coordinate reference system, CRS) to a GeoDataFrame in GeoPandas, you can set the crs attribute of the GeoDataFrame to the desired CRS. Here's how you can do it:

import geopandas as gpd
from shapely.geometry import Point

# Create a DataFrame (example)
data = {'City': ['New York', 'Los Angeles', 'Chicago'],
        'Latitude': [40.7128, 34.0522, 41.8781],
        'Longitude': [-74.0060, -118.2437, -87.6298]}
df = pd.DataFrame(data)

# Convert Latitude and Longitude columns to numeric type
df['Latitude'] = pd.to_numeric(df['Latitude'])
df['Longitude'] = pd.to_numeric(df['Longitude'])

# Create geometry column using shapely Point objects
geometry = [Point(xy) for xy in zip(df['Longitude'], df['Latitude'])]

# Create GeoDataFrame
gdf = gpd.GeoDataFrame(df, geometry=geometry)

# Set CRS (coordinate reference system)
# For example, let's use EPSG:4326 which is commonly used for latitude and longitude coordinates
gdf.crs = "EPSG:4326"

# Print GeoDataFrame
print(gdf)

In this example, after creating the GeoDataFrame gdf, the CRS is set to EPSG:4326, which corresponds to the WGS 84 geographic coordinate system commonly used with latitude and longitude coordinates. You can replace "EPSG:4326" with any other CRS that suits your data.

标签:CRS,reference,df,GeoPandas,system,GeoDataFrame,Latitude
From: https://www.cnblogs.com/alex-bn-lee/p/18011768

相关文章

  • Reference only code reading
    Referenceonlycodereading代码逻辑梳理Analysereference-onlycodeincontrolnetextensionofsdwebui.ControlNetHookTheentrypointinnercontrolnet_main_entrylookslike:#defcontrolnet_main_entry():self.latest_network=UnetHook(lowvram=is_low_v......
  • 存储故障,强制拉库报ORA-600 kcbzib_kcrsds_1处理---惜分飞
    联系:手机/微信(+8617813235971)QQ(107644445)标题:存储故障,强制拉库报ORA-600kcbzib_kcrsds_1处理作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]硬件故障,客户自行强制resetlogs库,报ORA-600kcbzib_kcrsds_1错误2024-01......
  • DPO: Direct Preference Optimization 直接偏好优化(学习笔记)
    学习参考:链接1  一、为什么要提出DPO在之前,我们已经了解到基于人类反馈的强化学习RLHF分为三个阶段:全监督微调(SFT)、奖励模型(RM)、强化学习(PPO)。但是RLHF面临缺陷:RLHF是一个复杂且经常不稳定的过程,首先拟合反映人类偏好的奖励模型,然后使用强化学习微调大型无监督LM,以最大......
  • 数据反序列化参数TypeReference
    使用jackson或者fastjson将json字符串反序列化成对象(以fastjson为例)TypeReference<AjaxResult<List<Person>>>typeReference=newTypeReference<AjaxResult<List<Person>>>(){};Stringjson="{\"code\":200,\"success\......
  • MacOS - Xcode 报referenced from:
    Xcode升级10之后项目错误:==================================================================================================================Link//Users/moyea/Desktop/NewSVN/BD34/BDPlayer/build/Release/Leawo\Blu-ray\Player.app/Contents/MacOS/LeawoBlu-rayP......
  • auto{x}与auto(x)---一位中国小伙为cppreference作出的贡献
      C++作为一门静态类型语言,是需要程序员声明变量类型的。然而来到了C++11,auto的诞生使得变量声明变得及为方便,尤其是对于比较长的模板类型,auto一定程度上为代码编写者减轻了负担。到了C++23,突然来了个新特性:auto{x}/auto(x),这又是个什么东西,它的motivation又是什么?   首先......
  • shared_preferences缓存
    封装import'dart:convert';import'package:shared_preferences/shared_preferences.dart';classJSpUtil{JSpUtil._internal();//私有的构造方法,防止外部实例化factoryJSpUtil()=>_instance;//工厂方法,返回JSpUtil唯一实例staticlatefinalJSpU......
  • Spring Framework Reference 5.3.27 - Core Technologies
    目录Chapter1.TheIoCContainerSpringIoC容器和bean介绍Chapter2.ResourcesChapter3.Validation,DataBinding,andTypeConversionChapter4.SpringExpressionLanguage(SpEL)Chapter5.AspectOrientedProgrammingwithSpringChapter6.SpringAOPAPIsChapter......
  • Spring Boot Reference 2.7.11
    目录UsingSpringBootBuildSystems代码风格配置类自动配置SpringBeansandDependencyInjection使用@SpringBootApplication注解RunningYourApplication开发者工具CoreFeatureCreatingYourOwnAuto-configuration加载自动配置候选项条件注解测试自动配置类创建自己的star......
  • eclipse的preferences中找不到server项
    最近重装了eclipse,但在使用eclipse载入Tomcat时发现Windows项中的preferences下找不到server项,通过查阅发现是没有安装相应插件,通过查询安装成功找到server项。具体步骤如下:1、选择Help-->InstallNewSoftware  2、点击add->在name中输入"Kepler"repository;location中输......