cuốn sách gpt4 ai đã làm

Hợp nhất (hợp nhất?) và đơn giản hóa/giảm bớt các bản ghi DbGeometry của GeoJson

In lại Tác giả: Vũ trụ không gian 更新时间:2023-11-03 14:51:07 28 4
mua khóa gpt4 Nike

我在一个表中有许多空间实体,其中有一个名为 Boundaries của geometry 字段。我想生成一个具有简化形状/几何图形的 GeoJson 文件。

这是我的第一次尝试:

var entities = await db.Entities.ToListAsync();

dynamic geoJson = new ExpandoObject();
geoJson.type = "FeatureCollection";

var features = new List();

foreach (var entity in entities)
{
// simplify (uses SqlGeometry.Reduce)
var simplified = Utilities.Geo.Simplify(entity.Boundaries, tolerance);

// convert to GeoJSON4EntityFramework.Feature with the appropriate Id
var feature = Utilities.Geo.GetFeature(simplified, entity.Id);

features.Add(feature);
}

geoJson.features = features;

return geoJson;

结果的问题在于,由于几何图形是单独简化的,因此边界并不常见,如下所示:

nhập mô tả hình ảnh ở đây

第二种尝试是先组合实体,然后简化,然后输出为 GeoJson:

var entities = await db.Entities.ToListAsync();

// bit of a hack to union all the boundaries
DbGeometry allBoundaries = null;
for (var i = 0; i < entities.Count; i++)
{
if (i == 0) allBoundaries = entities[i].Boundaries;
else allBoundaries = allBoundaries.Union(entities[i].Boundaries);
}

// simplify (uses SqlGeometry.Reduce)
var simplified = Utilities.Geo.Simplify(allBoundaries, tolerance);

dynamic geoJson = new ExpandoObject();
geoJson.type = "FeatureCollection";

var features = new List();

// convert to GeoJSON4EntityFramework.Feature with the (in)appropriate Id
var feature = Utilities.Geo.GetFeature(simplified, "ALL");

features.Add(feature);

geoJson.features = features;

return geoJson;

然而,尽管 said here 是什么,.Union 将实体合并为一个实体。这不会发生。 (然后我也没有机会在每个功能上放置一个 Id,所以现在只使用“ALL”)。结果是完全合并的形状:

nhập mô tả hình ảnh ở đây

所以问题是:我如何跨行组合边界,然后简化,然后生成一个特征集合,每个特征都有正确的 Id,可以在 MapShaper 中完成(如下所示)?

nhập mô tả hình ảnh ở đây

câu trả lời hay nhất

看起来这在 SQL Server 中是不可能的。

您需要将几何图形转换为拓扑结构,然后简化,然后匹配回原始几何图形以保留属性/属性/id/等。

参见:https://trac.osgeo.org/postgis/wiki/UsersWikiSimplifyWithTopologyExt

SQL Server 不支持拓扑。


biên tập

我正在处理下面的代码,它将多边形(不是多边形)转换为线串,合并线串以有效地获得拓扑层,然后对其进行简化。它工作得很好,但困难不在于将多线串转换为多面体,这可能需要 tool like this .

select
geometry::STGeomFromText(replace(replace(e1.boundaries.STAsText(), 'POLYGON (', 'LINESTRING '), '))', ')'), 4326)
.STUnion(geometry::STGeomFromText(replace(replace(e2.boundaries.STAsText(), 'POLYGON (', 'LINESTRING '), '))', ')'), 4326))
.STUnion(geometry::STGeomFromText(replace(replace(e3.boundaries.STAsText(), 'POLYGON (', 'LINESTRING '), '))', ')'), 4326))
.Reduce(0.1)
from entities e1
cross join entities e2
cross join entities e3
where e1.code = 'dc7'
and e2.code = 'dc6'
and e3.code = 'dc8'

nhập mô tả hình ảnh ở đây


biên tập

使用 NetTopologySuite,可以做到。我有 written it up here .sử dụng Polygonizer,您可以将线串转换回多边形。然后,您必须使用面积交集的比率将多边形与原始多边形匹配,然后(如果匹配)您可以重新关联属性。

关于c# - 合并(合并?)并简化/减少 GeoJson 的 DbGeometry 记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51755560/

28 4 0
không gian vũ trụ
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress