Multipart polyline to single part lines

本教程介绍如何在ArcGIS中使用VBA代码将多部分折线分解为单个线段。通过使用IGeometryCollection接口而非ISegmentCollection,可以避免创建过多的线段。代码示例展示了如何遍历选定的折线特征,将其分解,并存储为新的单一部分折线。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Breaking Up Polylines 

http://forums.esri.com/Thread.asp?c=93&f=987&t=74554&mc=4#msgid197545

 

It appears as though IGeometryCollection is the way to go here, rather than ISegmentCollection. I noticed that the "ISegmentCollection" version created 905 line segments (from 15 polylines). ISegmentCollection created a line for every Single PAIR of vertices - 905 straight, two vertex lines. 

There is no way I could have put this thing together at this point. Thanks for getting the ball rolling. 

Hopefully, this can be useful to other users. Multipart lines can be a huge pain when you don't want them. 

Sub ExplodePolyLines()

'

' From the original by Kirk Kuykendall.

'

Dim pUID As New UID

pUID.Value = "esricore.Editor"

 

Dim pEditor As IEditor

Set pEditor = Application.FindExtensionByCLSID(pUID)

 

If pEditor.EditState <> esriStateEditing Then

MsgBox "Make a shapefile editable."

Exit Sub

End If

 

Dim pEditlayers As IEditLayers

Set pEditlayers = pEditor

 

If pEditlayers.CurrentLayer.FeatureClass.ShapeType <> esriGeometryPolyline Then

Exit Sub

End If

 

Dim pFSel As IFeatureSelection

Set pFSel = pEditlayers.CurrentLayer

 

If pFSel.SelectionSet.Count = 0 Then

MsgBox "Select features to be broken up."

Exit Sub

End If

 

Dim pFCur As IFeatureCursor

pFSel.SelectionSet.Search Nothing, False, pFCur

 

pEditor.StartOperation

Dim pFeat As IFeature

Set pFeat = pFCur.NextFeature

Do Until pFeat Is Nothing

Dim pInGeomColl As IGeometryCollection

''' Dim pInSegColl As ISegmentCollection

''' Set pInSegColl = pFeat.ShapeCopy

Set pInGeomColl = pFeat.ShapeCopy

 

Application.StatusBar.Message(0) = "Exploding " & pFeat.OID

Dim l As Long

''' For l = 0 To pInSegColl.SegmentCount - 1

For l = 0 To pInGeomColl.GeometryCount - 1

''' Dim pOutSegColl As ISegmentCollection

''' Set pOutSegColl = New Polyline

Dim pOutGeomColl As IGeometryCollection

Set pOutGeomColl = New Polyline

''' pOutSegColl.AddSegment pInSegColl.Segment(l)

pOutGeomColl.AddGeometry pInGeomColl.Geometry(l)

Dim pOutFeat As IFeature

Set pOutFeat = pEditlayers.CurrentLayer.FeatureClass.CreateFeature

Dim k As Long

For k = 0 To pOutFeat.Fields.FieldCount - 1

If pOutFeat.Fields.Field(k).Editable Then

If pOutFeat.Fields.Field(k).Type <> esriFieldTypeGeometry Then

pOutFeat.Value(k) = pFeat.Value(k)

End If

End If

Next k

''' Set pOutFeat.Shape = pOutSegColl

Set pOutFeat.Shape = pOutGeomColl

pOutFeat.Store

Next l

pFeat.Delete

Set pFeat = pFCur.NextFeature

Loop

pEditor.StopOperation "Explode"

 

Dim pMxDoc As IMxDocument

Set pMxDoc = pEditor.Parent.Document

Dim pAV As IActiveView

Set pAV = pMxDoc.FocusMap

Dim lCacheID As Long

lCacheID = pAV.ScreenCacheID(esriViewGeoSelection, Nothing)

pAV.ScreenDisplay.Invalidate Nothing, True, lCacheID

MsgBox "Done"

End Sub

在使用 Spring Boot 开发文件上传功能时,可能会遇到 `Failed to parse multipart servlet request` 错误,其根本原因通常与临时文件存储路径或磁盘空间有关。以下是常见原因及解决方案: ### 1. 临时上传目录不可用或被清理 Spring Boot 使用内嵌的 Tomcat 服务器时,默认会将上传的文件写入临时目录,例如 `/tmp/tomcat.*`。如果该目录被系统清理或权限不足,将导致 `IOException` 错误[^2]。 **解决方案:** - **手动配置上传临时路径** 在 `application.properties` 或 `application.yml` 中设置自定义的临时目录,确保该目录存在且具有读写权限。 ```properties spring.servlet.multipart.location=/data/upload/tmp ``` 或者在 `application.yml` 中: ```yaml spring: servlet: multipart: location: /data/upload/tmp ``` - **验证目录权限** 确保指定的目录具有运行 Spring Boot 应用程序的用户权限,避免出现权限拒绝的问题。 ### 2. 磁盘空间不足或临时文件未被清理 当上传大量文件或大文件时,临时目录可能因磁盘空间不足导致写入失败。此外,Tomcat 的临时目录在每次重启时都会被清理,如果未正确重新创建,也可能导致异常。 **解决方案:** - 定期清理临时目录中的旧文件。 - 配置定时任务或使用外部存储机制来管理上传的临时文件。 ### 3. 文件大小超过限制 Spring Boot 默认对上传文件的大小有限制,如果上传的文件过大,将导致请求解析失败。 **解决方案:** - 调整 `application.properties` 中的文件大小限制: ```properties spring.servlet.multipart.max-file-size=10MB spring.servlet.multipart.max-request-size=100MB ``` 或者在 `application.yml` 中: ```yaml spring: servlet: multipart: max-file-size: 10MB max-request-size: 100MB ``` ### 4. 使用外部 Tomcat 时的配置差异 如果部署在外部 Tomcat 上,而不是使用内嵌的 Tomcat,临时目录的路径可能未正确配置,导致上传失败。 **解决方案:** - 在外部 Tomcat 的 `server.xml` 或 `context.xml` 中配置临时工作目录。 - 或者在 Spring Boot 应用中显式指定 `multipart.location`。 ### 示例代码:文件上传控制器 以下是一个典型的文件上传接口示例: ```java @RestController public class FileUploadController { @PostMapping("/upload") public ResponseEntity<String> handleFileUpload(@RequestParam("file") MultipartFile file) { if (file.isEmpty()) { return ResponseEntity.badRequest().body("File is empty"); } try { // 保存文件逻辑 String fileName = file.getOriginalFilename(); // 例如保存到指定路径 Path path = Paths.get("/data/upload/" + fileName); file.transferTo(path); return ResponseEntity.ok("File uploaded successfully: " + fileName); } catch (IOException e) { return ResponseEntity.status(500).body("Failed to store file"); } } } ``` ### 5. 日志排查建议 - 检查 Tomcat 的 `work` 目录是否存在且可写。 - 查看系统日志(如 `/var/log/messages` 或 `dmesg`)是否有磁盘空间不足或权限问题的提示。 - 在应用启动时输出当前使用的临时目录,确认是否与预期一致。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值