使用VB.NET。我想創建一個空間座標的字符串作爲參數查詢Web服務。座標需要從文本文件(GIS的標準輸出)中提取,該文件可以是任意長度的。Streamread將文本文件的一部分寫入字符串
Web服務需要以逗號分隔的「公知文本」格式查看座標對的字符串。例如。 -2.780299 53.373266,-2.780606 53.372617,-2.782207 53.370392,-2.784552 53.362061
(表面上類似於一個問題問here)
的文本文件,在這個結構。重申我需要一個只包含座標(用逗號分隔的對)在「161」之後和「筆」之前的字符串。儘管「地區」一詞是161,但它並不是一個一致的數字。
Version 300
Charset "WindowsLatin1"
Delimiter ","
CoordSys Earth Projection 1, 104
Columns 1
id Char(10)
Data
Region 1
161
-2.780299 53.373266
-2.780312 53.373235
-2.780535 53.372905
-2.780606 53.372617
-2.780844 53.372234
-2.781227 53.371664
-2.781239 53.371646
-2.781409 53.371407
-2.781779 53.3709
-2.782101 53.370549
-2.782204 53.370402
-2.782207 53.370392
-2.781142 53.37014
-2.780263 53.369894
-2.780314 53.369698
-2.780378 53.36953
-2.780453 53.369362
-2.780532 53.369223
-2.780611 53.369101
-2.780826 53.368803
-2.781468 53.367978
-2.781768 53.367608
-2.78184 53.367497
-2.781863 53.367458
-2.781806 53.367446
-2.781751 53.367435
-2.781712 53.367428
-2.781733 53.367398
-2.781753 53.367369
-2.781847 53.36723
-2.781949 53.367077
-2.781866 53.367046
-2.781492 53.366907
-2.781182 53.36682
-2.781269 53.366388
-2.780878 53.366173
-2.781063 53.365894
-2.781693 53.365255
-2.782277 53.364606
-2.782594 53.364311
-2.782652 53.364272
-2.782676 53.364242
-2.782687 53.364205
-2.78268 53.364158
-2.782643 53.364085
-2.782643 53.364035
-2.782943 53.363738
-2.783346 53.363266
-2.783736 53.362905
-2.784254 53.362383
-2.784552 53.362061
-2.784617 53.361959
-2.784113 53.361843
-2.783923 53.361764
-2.783968 53.361533
-2.783978 53.361504
-2.784358 53.361226
-2.784823 53.360723
-2.784833 53.360712
-2.785201 53.360193
-2.785831 53.359301
-2.785832 53.359301
-2.786182 53.358787
-2.786484 53.358288
-2.786318 53.35821
-2.787152 53.356913
-2.787255 53.356614
-2.787199 53.356333
-2.787559 53.356315
-2.790294 53.356237
-2.791854 53.35619
-2.792974 53.356147
-2.794152 53.356092
-2.794698 53.35605
-2.79521 53.356012
-2.795333 53.356006
-2.795732 53.355982
-2.79586 53.355973
-2.796257 53.355942
-2.797842 53.355898
-2.797931 53.355936
-2.798299 53.355921
-2.798399 53.355926
-2.798727 53.355937
-2.799055 53.355943
-2.799382 53.355944
-2.799711 53.355942
-2.799919 53.355939
-2.800248 53.355929
-2.800575 53.355915
-2.800901 53.355898
-2.802135 53.355819
-2.803302 53.355749
-2.804436 53.355658
-2.805646 53.355515
-2.807964 53.355207
-2.809126 53.355058
-2.809593 53.354684
-2.810372 53.354184
-2.81147 53.353449
-2.81147 53.353444
-2.811472 53.353428
-2.811474 53.353413
-2.811477 53.353397
-2.811481 53.353381
-2.811487 53.353365
-2.811492 53.35335
-2.811506 53.353325
-2.811538 53.35328
-2.811578 53.353237
-2.811617 53.353193
-2.811622 53.353188
-2.811663 53.353145
-2.811704 53.353101
-2.811749 53.353069
-2.811852 53.352994
-2.811875 53.352979
-2.811983 53.352906
-2.812094 53.352834
-2.812209 53.352764
-2.812324 53.352695
-2.812443 53.352629
-2.813163 53.352174
-2.81362 53.351928
-2.813782 53.352417
-2.814005 53.353349
-2.814147 53.354287
-2.814206 53.355228
-2.814183 53.356169
-2.814077 53.357109
-2.813889 53.358043
-2.813619 53.358971
-2.813268 53.359889
-2.812837 53.360795
-2.812327 53.361686
-2.81174 53.36256
-2.811077 53.363414
-2.81034 53.364247
-2.809531 53.365055
-2.808652 53.365837
-2.807706 53.366591
-2.806694 53.367313
-2.805621 53.368004
-2.804489 53.36866
-2.803301 53.369279
-2.802059 53.369861
-2.800769 53.370403
-2.799433 53.370904
-2.798055 53.371362
-2.796638 53.371777
-2.795187 53.372147
-2.793705 53.372471
-2.792197 53.372749
-2.790666 53.372979
-2.789118 53.37316
-2.787556 53.373294
-2.785984 53.373378
-2.784407 53.373413
-2.782829 53.373399
-2.781254 53.373335
-2.780299 53.373266
Pen (2,2,16711680)
Brush (5,16711680)
Center -2.797227 53.362684
一如既往的任何方向的幫助將不勝感激。現有的代碼在舊的基於SOAP的服務上工作,如下所示。但是,它使用了一個自定義庫,我將不再能夠訪問並且不知道如何替換。它還利用了不再被新服務認可的空間系統(東和北)。
有可能我能夠在程序內轉換空間系統,所以如果只有在不需要NBN庫的情況下才能實現這個工作,那麼這將是朝着正確方向邁出的一大步。
Function GetPolyFromMIF(ByVal strMIF As String) As NBN.Polygon
Dim sr As StreamReader = New StreamReader(strMIF)
Dim sLine As String = sr.ReadLine
Dim iCoords As Integer
Dim iCoord As Integer
Dim sCoords() As String
Dim dblEasting As Double
Dim dblNorthing As Double
Dim coords() As NBN.Coordinate
Dim bPolyComplete As Boolean = False
Dim poly As NBN.Polygon = New NBN.Polygon
Do While Not sr.EndOfStream And Not bPolyComplete
If sLine.StartsWith("Region") Then
iCoords = Convert.ToInt16(sr.ReadLine)
ReDim coords(iCoords)
For iCoord = 1 To iCoords
sCoords = sr.ReadLine.Split(" ")
dblEasting = Convert.ToDouble(sCoords(0))
dblNorthing = Convert.ToDouble(sCoords(1))
coords(iCoord - 1) = New NBN.Coordinate
coords(iCoord - 1).x = dblEasting
coords(iCoord - 1).y = dblNorthing
Next
poly.srs = NBN.SpatialReferenceSystem.osgb_BNG
Dim boundary As NBN.PolygonBoundary = New NBN.PolygonBoundary
boundary.Ring = coords
poly.Boundary = boundary
bPolyComplete = True
Else
sLine = sr.ReadLine
End If
Loop
Return poly
End Function
非常感謝您的回覆。我沒有機會嘗試你的解決方案,但只是閱讀你的解決方案,我想我可能會有些困惑。文本文件格式在所示的結構中(每個座標點在一個單獨的行上),但我不需要for的集合,而是需要所有點(描述多邊形)的單個字符串。每個座標/行用逗號分隔。我可能可以使用您發佈的代碼,但請耐心等待! – benj 2014-10-02 17:18:36
正則表達式在識別要提取的行中特別有用。我們需要對代碼進行一些修改才能符合我的最終用途,但大多數情況與此解決方案中的相同。歡呼Wizengamot! – benj 2014-10-10 09:11:44