我试图自己解决问题,但我无法解决,我试图以您可以想象的每种格式运行此代码,并且在ArcGIS Pro软件中也一样,我找不到此错误消息在任何其他问题上。从类似的问题来看,似乎有些数据文件可能丢失了?
import geopandas as gpd
import json
import numpy as np
from shapely.geometry import LineString, Point, box
import ast
from pyproj import Proj
paths = road_features.SHAPE.map(lambda x: np.array(ast.literal_eval(x)["paths"][0]))
pathLineStrings = paths.map(LineString)
gdf = gpd.GeoDataFrame(road_features,geometry=pathLineStrings)
#gdf.crs = {'init': 'epsg:3857'}
gdf.crs = {'init': 'epsg:4326'}
gdf = gdf.to_crs({'init': 'epsg:4326'})
我收到此错误
RuntimeError: b'no arguments in initialization list'
我也在arcgis pro中尝试过,我也得到了
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\geopandas\geodataframe.py", line 443, in to_crs
geom = df.geometry.to_crs(crs=crs, epsg=epsg)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\geopandas\geoseries.py", line 304, in to_crs
proj_in = pyproj.Proj(self.crs, preserve_units=True)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\pyproj\__init__.py", line 362, in __new__
return _proj.Proj.__new__(self, projstring)
File "_proj.pyx", line 129, in _proj.Proj.__cinit__
RuntimeError: b'no arguments in initialization list'
答案 0 :(得分:5)
问题可能出在Windows平台上Anaconda的pyproj安装中。就像史蒂芬所说,解决方案是在“ datadir.py”(位于... Anaconda3 \ Lib \ site-packages \ pyproj中)中编辑路径。
正确的路径是“ ... / Anaconda3 / Library / share”。确保完整路径完整(可能包含用户名等)。我还需要将\更改为/。 这种变化对我有用。是的,进行此更改后,有必要重新启动Spyder(或您使用的任何设备)。
答案 1 :(得分:1)
使用Geopandas,尝试这样做(应该可以使用):
gdf = gpd.GeoDataFrame(gdf, geometry=gdf['geometry'])
gdf.crs = {'init' :'epsg:2154'}
gdf = gdf.to_crs({'init' :'epsg:4326'})
您应该重新定义地理数据框, 然后定义初始地理参考 并最终将其转换为好的。 如果有的话,不要忘记删除NaN。
答案 2 :(得分:0)
是否定义了初始crs
?
仅当我仅通过epsg命令gdf.to_crs('epsg:4326')
时,才遇到相同的问题。
如图所示
my_geoseries.crs = {'init' :'epsg:3857'}
应该是第一步,然后转换为
gdf = gdf.to_crs({'init': 'epsg:4326'})
如果您使用的是ArcGIS,还可以在属性中检查是否定义了初始epsg?
很好,这就是答案
答案 3 :(得分:0)
确保这是pyproj错误,而不是geopandas。
public class SinchService extends Service {
private static final String APP_KEY = "my app key here";
private static final String APP_SECRET = "my app secret here";
private static final String ENVIRONMENT = "sandbox.sinch.com";
public static final int MESSAGE_PERMISSIONS_NEEDED = 1;
public static final String REQUIRED_PERMISSION = "REQUIRED_PESMISSION";
public static final String MESSENGER = "MESSENGER";
private Messenger messenger;
public static final String CALL_ID = "CALL_ID";
static final String TAG = SinchService.class.getSimpleName();
private PersistedSettings mSettings;
private SinchServiceInterface mSinchServiceInterface = new SinchServiceInterface();
private SinchClient mSinchClient;
private StartFailedListener mListener;
@Override
public void onCreate() {
super.onCreate();
mSettings = new PersistedSettings(getApplicationContext());
attemptAutoStart();
}
private void attemptAutoStart() {
String userName = mSettings.getUsername();
if (!userName.isEmpty() && messenger != null) {
start(userName);
}
}
private void createClient(String username) {
mSinchClient = Sinch.getSinchClientBuilder().context(getApplicationContext()).userId(username)
.applicationKey(APP_KEY)
.applicationSecret(APP_SECRET)
.environmentHost(ENVIRONMENT).build();
mSinchClient.setSupportCalling(true);
mSinchClient.setSupportManagedPush(true);
mSinchClient.setSupportActiveConnectionInBackground(true);
mSinchClient.startListeningOnActiveConnection();
mSinchClient.addSinchClientListener(new MySinchClientListener());
mSinchClient.getCallClient().addCallClientListener(new SinchCallClientListener());
}
@Override
public void onDestroy() {
if (mSinchClient != null && mSinchClient.isStarted()) {
mSinchClient.terminate();
}
super.onDestroy();
}
private void start(String username) {
boolean permissionsGranted = true;
if (mSinchClient == null) {
mSettings.setUsername(username);
createClient(username);
}
try {
//mandatory checks
mSinchClient.checkManifest();
} catch (MissingPermissionException e) {
permissionsGranted = false;
if (messenger != null) {
Message message = Message.obtain();
Bundle bundle = new Bundle();
bundle.putString(REQUIRED_PERMISSION, e.getRequiredPermission());
message.setData(bundle);
message.what = MESSAGE_PERMISSIONS_NEEDED;
try {
messenger.send(message);
} catch (RemoteException e1) {
e1.printStackTrace();
}
}
}
if (permissionsGranted) {
Log.d(TAG, "Starting SinchClient");
mSinchClient.start();
}
}
private void stop() {
if (mSinchClient != null) {
mSinchClient.terminate();
mSinchClient = null;
}
}
private boolean isStarted() {
return (mSinchClient != null && mSinchClient.isStarted());
}
@Override
public IBinder onBind(Intent intent) {
messenger = intent.getParcelableExtra(MESSENGER);
return mSinchServiceInterface;
}
public class SinchServiceInterface extends Binder {
public Call callUser(String userId) {
return mSinchClient.getCallClient().callUser(userId);
}
public String getUserName() {
return mSinchClient != null ? mSinchClient.getLocalUserId() : "";
}
public void retryStartAfterPermissionGranted() { SinchService.this.attemptAutoStart(); }
public boolean isStarted() {
return SinchService.this.isStarted();
}
public void startClient(String userName) {
start(userName);
}
public void stopClient() {
stop();
}
public void setStartListener(StartFailedListener listener) {
mListener = listener;
}
public Call getCall(String callId) {
return mSinchClient.getCallClient().getCall(callId);
}
public AudioController getAudioController() {
if (!isStarted()) {
return null;
}
return mSinchClient.getAudioController();
}
public NotificationResult relayRemotePushNotificationPayload(final Map payload) {
if (mSinchClient == null && !mSettings.getUsername().isEmpty()) {
createClient(mSettings.getUsername());
} else if (mSinchClient == null && mSettings.getUsername().isEmpty()) {
Log.e(TAG, "Can't start a SinchClient as no username is available, unable to relay push.");
return null;
}
return mSinchClient.relayRemotePushNotificationPayload(payload);
}
}
public interface StartFailedListener {
void onStartFailed(SinchError error);
void onStarted();
}
private class MySinchClientListener implements SinchClientListener {
@Override
public void onClientFailed(SinchClient client, SinchError error) {
if (mListener != null) {
mListener.onStartFailed(error);
}
mSinchClient.terminate();
mSinchClient = null;
}
@Override
public void onClientStarted(SinchClient client) {
Log.d(TAG, "SinchClient started");
if (mListener != null) {
mListener.onStarted();
}
}
@Override
public void onClientStopped(SinchClient client) {
Log.d(TAG, "SinchClient stopped");
}
@Override
public void onLogMessage(int level, String area, String message) {
switch (level) {
case Log.DEBUG:
Log.d(area, message);
break;
case Log.ERROR:
Log.e(area, message);
break;
case Log.INFO:
Log.i(area, message);
break;
case Log.VERBOSE:
Log.v(area, message);
break;
case Log.WARN:
Log.w(area, message);
break;
}
}
@Override
public void onRegistrationCredentialsRequired(SinchClient client,
ClientRegistration clientRegistration) {
}
}
private class SinchCallClientListener implements CallClientListener {
@Override
public void onIncomingCall(CallClient callClient, Call call) {
Log.d(TAG, "onIncomingCall: " + call.getCallId());
Intent intent = new Intent(SinchService.this, IncomingCallScreenActivity.class);
intent.putExtra(CALL_ID, call.getCallId());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SinchService.this.startActivity(intent);
}
}
private class PersistedSettings {
private SharedPreferences mStore;
private static final String PREF_KEY = "Sinch";
public PersistedSettings(Context context) {
mStore = context.getSharedPreferences(PREF_KEY, MODE_PRIVATE);
}
public String getUsername() {
return mStore.getString("Username", "");
}
public void setUsername(String username) {
SharedPreferences.Editor editor = mStore.edit();
editor.putString("Username", username);
editor.commit();
}
}
}
public class FcmListenerService extends FirebaseMessagingService {
private final String PREFERENCE_FILE = "com.sinch.android.rtc.sample.push.shared_preferences";
SharedPreferences sharedPreferences;
@Override
public void onMessageReceived(RemoteMessage remoteMessage){
Map data = remoteMessage.getData();
if (SinchHelpers.isSinchPushPayload(data)) {
new ServiceConnection() {
private Map payload;
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Context context = getApplicationContext();
sharedPreferences = context.getSharedPreferences(PREFERENCE_FILE, Context.MODE_PRIVATE);
if (payload != null) {
SinchService.SinchServiceInterface sinchService = (SinchService.SinchServiceInterface) service;
if (sinchService != null) {
NotificationResult result = sinchService.relayRemotePushNotificationPayload(payload);
// handle result, e.g. show a notification or similar
// here is example for notifying user about missed/canceled call:
if (result.isValid() && result.isCall()) {
CallNotificationResult callResult = result.getCallResult();
if (callResult != null && result.getDisplayName() != null) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(callResult.getRemoteUserId(), result.getDisplayName());
editor.commit();
}
if (callResult.isCallCanceled()) {
String displayName = result.getDisplayName();
if (displayName == null) {
displayName = sharedPreferences.getString(callResult.getRemoteUserId(),"n/a");
}
createNotification(displayName != null && !displayName.isEmpty() ? displayName : callResult.getRemoteUserId());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
context.deleteSharedPreferences(PREFERENCE_FILE);
}
}
}
}
}
payload = null;
}
@Override
public void onServiceDisconnected(ComponentName name) {}
public void relayMessageData(Map<String, String> data) {
payload = data;
getApplicationContext().bindService(new Intent(getApplicationContext(), SinchService.class), this, BIND_AUTO_CREATE);
}
}.relayMessageData(data);
}
}
private void createNotificationChannel() {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Sinch";
String description = "Incoming Sinch Push Notifications.";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(getResources().getString(R.string.default_notification_channel_id), name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}
private void createNotification(String userId) {
createNotificationChannel();
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,
new Intent(getApplicationContext(), LoginActivity.class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext(), getResources().getString(R.string.default_notification_channel_id))
.setSmallIcon(R.drawable.icon)
.setContentTitle("Missed call from:")
.setContentText(userId);
mBuilder.setContentIntent(contentIntent);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}
如果上述运行时错误相同,则可以确定此错误是由于pyproj引起的。
只需conda删除pyproj并使用pip进行安装即可。
pip安装pyproj
至少这对我有用。
答案 4 :(得分:0)
我正在使用Pycharm。 我不得不同时使用史通史的言论和多雷加雷的言论。
import pyproj
pyproj.Proj("+init=epsg:4326")
> RuntimeError: b'no arguments in initialization list'
据石史(Stone Shi)说,以上证明它是一个pyproj err。 所以我用了Pycharm-> Settings并重新安装了pyproj。 然后
import pyproj
pyproj.Proj("+init=epsg:4326")
> RuntimeError: b'no arguments in initialization list'
所以,这是pyproj错误,但是 Pycharm->重新安装pyproj的设置对我没有帮助。
然后我编辑了C:\ Anaconda3 \ Lib \ site-packages \ pyproj \ datadir.py 来自:
pyproj_datadir="C:/Anaconda3\share\proj"
多雷加里的:
pyproj_datadir="C:\Anaconda3\Library\share"
然后再次测试:
import pyproj
pyproj.Proj("+init=epsg:4326")
>Process finished with exit code 0
没有运行时错误!
然后在我的
上进行测试wgs84 = data.to_crs({'init': 'epsg:4269'})
>Process finished with exit code 0
答案 5 :(得分:0)
我遇到了同样的错误。我使用的是Python 3.6.3版和Geopandas 0.4.0版。通过使用以下而不是df = df.to_crs({'init': 'epsg:4326'})
来解决此问题:
df = df.to_crs(epsg=4326)
答案 6 :(得分:0)
对于我升级pyproj
和geopandas
而言,已解决此问题:
pip install pyproj --upgrade
pip install geopandas --upgrade
答案 7 :(得分:0)
你可以直接使用 pip 强制重新安装 pyproj
pip install --upgrade --force-reinstall pyproj
而不是卸载并重新安装,这也会卸载所有依赖库