Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: graphical shape list of points floating point values reduce amount number points keeping shape
;------------------------------------------------------------------------------------------------------------------------------------------ ; (c)20101215.Detlev Dalitz. ;------------------------------------------------------------------------------------------------------------------------------------------ ; There is a graphical shape given by a list of points (floating point values). ; The goal is to reduce the amount of points while keeping the shape. ; ; Original list (external text file): ; -22.60299683;-23.34320068 ; -22.60299683;-23.34457397 ; -22.60299683;-23.34457397 ; -22.60437012;-23.34457397 ; -22.60437012;-23.34457397 ; -22.60437012;-23.34594727 ; -22.60437012;-23.34594727 ; -22.60437012;-23.34732056 ; -22.60437012;-23.34732056 ; -22.60574341;-23.34732056 ; -22.60574341;-23.34732056 ; -22.60574341;-23.34594727 ; -22.60574341;-23.34594727 ; -22.60574341;-23.34457397 ; -22.60574341;-23.34457397 ; -22.60574341;-23.34320068 ; -22.60574341;-23.34320068 ; -22.60574341;-23.34182739 ; -22.60574341;-23.34182739 ; -22.60574341;-23.3404541 ; -22.60574341;-23.3404541 ; -22.60437012;-23.3404541 ; -22.60437012;-23.3404541 ; -22.60437012;-23.34182739 ; -22.60437012;-23.34182739 ; -22.60437012;-23.34320068 ; -22.60437012;-23.34320068 ; -22.60299683;-23.34320068 ; ; Expected result: ; -22.60299683;-23.34320068 ; -22.60299683;-23.34457397 ; -22.60437012;-23.34457397 ; -22.60437012;-23.34732056 ; -22.60574341;-23.34732056 ; -22.60574341;-23.3404541 ; -22.60437012;-23.3404541 ; -22.60437012;-23.34320068 ; -22.60299683;-23.34320068 ;------------------------------------------------------------------------------------------------------------------------------------------ DirChange (DirScript ()) strFileFltPointsIn = "ListFltPointsIn.txt" strFileFltPointsOut = "ListFltPointsOut.txt" ; Read the item list of points from external text file into a string variable. strItemListLong = FileGet (strFileFltPointsIn) strItemListLong = StrTrim (StrReplace (strItemListLong, @CRLF, @TAB)) ; Remove leading and trailing empty lines. ; Prepare the item list of points for later usage by ArrayFileGetCSV. strFileTemp = FileCreateTemp ("WB") strItemList = StrReplace (strItemListLong, @TAB, @CRLF) intBytesWritten = FilePut (strFileTemp, strItemList) ; Do the math. arrP = ArrayFileGetCSV (strFileTemp, 0, ";") intLast = ArrInfo (arrP, 1) - 1 intI = 1 While intI < intLast Switch @TRUE ; Remove duplicate points. Case arrP[intI, 0] == arrP[intI - 1, 0] && arrP[intI, 1] == arrP[intI - 1, 1] Case arrP[intI, 0] == arrP[intI + 1, 0] && arrP[intI, 1] == arrP[intI + 1, 1] ArrayRemove (arrP, intI, 1) intLast = intLast - 1 Break ; Skip turning points. Case arrP[intI, 0] == arrP[intI + 1, 0] && arrP[intI, 1] == arrP[intI - 1, 1] Case arrP[intI, 0] == arrP[intI - 1, 0] && arrP[intI, 1] == arrP[intI + 1, 1] intI = intI + 1 Break ; Remove inline points. Case @TRUE ArrayRemove (arrP, intI, 1) intLast = intLast - 1 EndSwitch EndWhile ; Write the reduced item list of points to external text file. intBytesWritten = ArrayFilePutCSV (strFileFltPointsOut, arrP, ";", @FALSE, 2) ; Display result. strItemListShort = FileGet (strFileFltPointsOut) strItemListShort = StrTrim (StrReplace (strItemListShort, @CRLF, @TAB)) ; Remove leading and trailing empty lines. intItemsLong = ItemCount (strItemListLong, @TAB) intItemsShort = ItemCount (strItemListShort, @TAB) strItemListLong = StrReplace (strItemListLong, @TAB, @LF) strItemListShort = StrReplace (strItemListShort, @TAB, @LF) Pause ("Result|ItemsLong=" : intItemsLong : "|ItemsShort=" : intItemsShort, strItemListLong : @LF : @LF : strItemListShort) Run (strFileFltPointsIn, "") Run (strFileFltPointsOut, "") :CANCEL blnResult = FileDelete (strFileTemp) Exit
Article ID: W17944
Filename: Reduce Shape Point List.txt
File Created: 2010:12:15:08:40:18
Last Updated: 2010:12:15:08:40:18