我有一个roadfollowing
表,其中包含列
COLUMN geom geometry(LineString,4326);
我还有一个sub_polygon
表,其中包含一列
COLUMN geom geometry(MultiPolygon,4326);
我想从存储在sub_polygon
表中的线串中减去roadfollowing
中存储的多边形,并使用这些新数据更新表。
我尝试执行以下查询:
WITH RESULTS as (
SELECT ST_Difference(public.roadnetwork.geom, public.sub_polygon.geom)
FROM public.roadnetwork, public.sub_polygon
),
FILTERED_RESULTS as (
SELECT RESULTS.st_difference FROM RESULTS where GeometryType(RESULTS.st_difference) <> 'GEOMETRYCOLLECTION'
)
UPDATE public.roadnetwork
SET geom = FILTERED_RESULTS.st_difference
FROM FILTERED_RESULTS;
但我收到以下错误:
ERROR: Geometry type (MultiLineString) does not match column type (LineString)
我修改了查询以便以字符串格式检查结果:
WITH RESULTS as (
SELECT ST_Difference(public.roadnetwork.geom, public.sub_polygon.geom)
FROM public.roadnetwork, public.sub_polygon
),
FILTERED_RESULTS as (
SELECT ST_AsText(RESULTS.st_difference) FROM RESULTS where GeometryType(RESULTS.st_difference) <> 'GEOMETRYCOLLECTION'
)
SELECT * from FILTERED_RESULTS;
我可以看到结果中有一些MULTILINESTRING
,无法在roadnetwork.geom
列中复制,因为数据不一致:
...
MULTILINESTRING((51.5054201 25.3462475,51.505411 25.3462656,51.5052981 25.3464467,51.5051894 25.3466039,51.5049763 25.3469023,51.5048058 25.347141,51.5046538 25.347324,51.5044476 25.3475493,51.5041983 25.3478035,51.5038722 25.3481104,51.5035605 25.3483885,51.509695 25.3489269,51.5026179 25.3492445,51.5022888 25.349556),(51.5022888 25.349556,51.5022898 25.3495551),(51.5022888 25.349556,51.5017303 25.3500517))
LINESTRING(51.5017303 25.3500517,51.5014725 25.3502989,51.5013472 25.3504121)
LINESTRING(51.5013472 25.3504121,51.501175 25.3505679)
...
如何更新我的查询以便将MULTILINESTRING
转换为LINESTRING
,以便我可以成功更新我的表格?
答案 0 :(得分:1)
您可以使用st_dump将MultiLineStrings扩展为LineStrings。
像这样的东西
public class FcmMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String title = remoteMessage.getNotification().getTitle();
final String message = remoteMessage.getNotification().getBody();
if (title.contains("Added")) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(
new Runnable() {
@Override
public void run() {
Log.d("webUrl",""+MainActivity.mWebview.getUrl());
if(MainActivity.mWebview.getUrl().contains("http://example.com")) {
Toast.makeText(FcmMessagingService.this, message, Toast.LENGTH_SHORT).show();
MainActivity.reLoad();
}
}
}
);
}else{
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("value", "kh");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri sounduri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(message);
notificationBuilder.setSmallIcon(R.mipmap.ic_icon);
notificationBuilder.setSound(sounduri);
notificationBuilder.setAutoCancel(true);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(0);
notificationManager.notify(0, notificationBuilder.build());
}
}
}