PROBLEM
ArcView displays ArcCAD coverages at the incorrect location.
An XY shift has been applied to the ArcCAD coverage. ArcView does not recognize the XY shift, causing the data to be displayed incorrectly.
Code:
' Name: View.ApplyShift
' Title: apply the shift from a shifted ArcCAD coverage.
' Topics: GeoData
' Description: Shifts features in the current active Theme in the
' X and Y distance retrived from the coverage. A new theme is created
' as a result of the shift. Only the selected features will be moved.
' If there are no selected features then all features in the theme will
' be moved. The units of the xy shift are the same units as the unprojected
' source geometry.
'
' Requires: A View with one active Theme.
theView = av.GetActiveDoc
srcnames = SourceDialog.Show("")
for each n in srcnames
theTheme = Theme.Make(n)
theView.AddTheme(theTheme)
theTheme.setactive(TRUE)
theTheme = theView.GetActiveThemes.Get(0)
theCover = theTheme.GetSrcName.GetFileName.GetFullName
thestring = theCover.asstring+"\xyshift.dbf"
f = File.Exists(thestring.asfilename)
if (f = true) then
shiftyes = msgbox.YesNo("This ArcCAD coverage "+theTheme.asstring.quote+" has an xyshift."+nl+"Do you what this applied to the view?","",true)
if (shiftyes = TRUE) then
v = Vtab.make(theString.asfilename,FALSE,FALSE)
xField = v.findField("xshift")
if (xField.asstring = "Nil") then
msgbox.info("There is no Xshift value."+nl+"Please check the xyshift.dbf file in the coverage."+nl+"Be sure that this is an apropriate file.","error")
exit
end
xshift = v.ReturnValue(xField,0)
xtype = xshift.getclass.getclassname
if (not(xtype = "number")) then
msgbox.info("There is no Yshift value."+nl+"Please check the xyshift.dbf file in the coverage."+nl+"Be sure that this is an apropriate file.","error")
exit
end
yField = v.findField("yshift")
if (yfield.asstring = "NIL") then
msgbox.info("There is no Yshift value."+nl+"Please check the xyshift.dbf file in the coverage."+nl+"Be sure that this is an apropriate file.","error")
exit
end
yshift = v.ReturnValue(yField,0)
ytype = yshift.getclass.getclassname
if (not(ytype = "number")) then
msgbox.info("There is no Yshift value."+nl+"Please check the xyshift.dbf file in the coverage."+nl+"Be sure that this is an apropriate file.","error")
exit
end
defaultName = FN.Make("$HOME").MakeTmp("theme","shp")
shpFileName = FileDialog.Put( defaultName,"*.shp","Output Shape File" )
if (shpFileName = Nil) then
exit
end
shpFileName.SetExtension("shp")
if (xShift = Nil) then
msgbox.info("There is no Xshift value."+nl+"Please check the xyshift.dbf file in the coverage."+nl+"Be sure that there this is an apropriate file.","error")
exit
end
if (yShift = Nil) then
msgbox.info("There is no Yshift value."+nl+"Please check the xyshift.dbf file in the coverage."+nl+"Be sure that there this is an apropriate file.","error")
exit
end
shapeType = theTheme.GetFtab.FindField("Shape").GetType
if (shapeType = #FIELD_SHAPELINE) then
outFTab = FTab.MakeNew( shpFileName, Polyline )
elseif (shapeType = #FIELD_SHAPEMULTIPOINT) then
outFTab = FTab.MakeNew( shpFileName, Multipoint )
elseif (shapeType = #FIELD_SHAPEPOINT) then
outFTab = FTab.MakeNew( shpFileName, Point )
elseif (shapeType = #FIELD_SHAPEPOLY) then
outFTab = FTab.MakeNew( shpFileName, Polygon )
end
inShapeField = theTheme.GetFtab.FindField("Shape")
outShapeField = outFTab.FindField("Shape")
inFTab = theTheme.GetFTab
inFieldList = inFTab.GetFields
outFieldList = inFieldList.DeepClone
outFieldList.Remove(0) ' omit the shape field...
outFTab.AddFields( outFieldList )
if (inFTab.GetSelection.Count = 0) then
theRecordsToShift = inFTab
numRecs = inFTab.GetNumRecords
else
theRecordsToShift = inFTab.GetSelection
numRecs = theRecordsToShift.Count
end
for each rec in theRecordsToShift
theShape = theTheme.GetFtab.ReturnValue( inShapeField, rec )
newShape = theShape.Move(xShift, yShift)
newRec = outFtab.AddRecord
outFTab.SetValue( outShapeField, newRec, newShape )
fieldPtr = 0
for each fOut in outFieldList
fieldPtr = fieldPtr + 1
fIn = inFieldList.Get( fieldPtr )
outFTab.SetValue( fOut, newRec, inFTab.ReturnValue( fIn, rec ) )
end
end
outFtab.Flush
if (MsgBox.YesNo("Add shapefile as theme to a view?","XY Shift", true).Not) then
exit
end
viewList = {}
for each d in av.GetProject.GetDocs
if (d.Is(View)) then
viewList.Add( d )
end
end
viewList.Add("<New View>")
addToView = MsgBox.ListAsString( viewList,"Add Theme to:", "XY Shift" )
if (addToView <> nil) then
if (addToView = "<New View>") then
addToView = View.Make
addToView.GetWin.Open
end
shiftedTheme = FTheme.Make( outFTab )
addToView.AddTheme( shiftedTheme )
addToView.GetWin.Activate
end
end
end
end
Article ID:000005141
Get help from ArcGIS experts
Download the Esri Support App