The only output format permitted by the ArcMap bookmark manager (v10.7) is an "ArcGIS place file (*.dat)" which is not entirely human-readable when opened in a text editor.
What is the file structure of an ArcGIS Place File? suggests it may not be possible to access content directly and probably requires ArcObjects to extract bookmark info.
Is there another way to transfer bookmarks from ArcMap so that they are suitable to be read by QGIS?
2 Answers 2
Rather than output bookmarks as an ArcGIS Place File (*.dat
) you can use the ListBookmarks function of ArcPy which:
Returns a Python list of named tuples that provide access to each spatial bookmark's name and extent.
With that simple data structure available within Python you could write to a file format of your choice or just read it direct using PyQGIS.
-
I'm running into trouble getting the bookmarks into QGIS (the other half of my question). Should I append to my original question or retitle this one and start a new one?CreekGeek– CreekGeek2021年05月06日 05:29:03 +00:00Commented May 6, 2021 at 5:29
-
1@CreekGeek I think we already have a focused Q&A asked and answered here so I think the best way forward is to ask a new question. I'll re-frame this one as "Outputting bookmarks in TXT file using ArcPy" and suggest you ask the new question about "Inputting bookmarks from TXT file using PyQGIS".2021年05月06日 05:51:54 +00:00Commented May 6, 2021 at 5:51
-
Sounds good. Cheers.CreekGeek– CreekGeek2021年05月06日 07:58:49 +00:00Commented May 6, 2021 at 7:58
Working from @PolyGeo's answer, here's some code that gets the info out of ArcMap:
import arcpy
srcPath = "D:\\SomeFolder\\Data\\"
srcFile = "MyMap.mxd"
# set working mxd
mxd = arcpy.mapping.MapDocument(srcPath+srcFile)
with open(srcPath+'filename.txt', "w") as outtxt:
for df in arcpy.mapping.ListDataFrames(mxd,"*"):
for bkmk in arcpy.mapping.ListBookmarks(mxd, "", df):
e = bkmk.extent
CRS=2193
tmp_lst = list((bkmk.name.encode("utf-8").replace(" ","").replace("-","_"),"SomeName",e.XMin,e.YMin,e.XMax,e.YMax,CRS))
str_lst = ','.join(str(t) for t in tmp_lst)
outtxt.write(str_lst+"\n")
posted earlier today...works, but not as tidy:
out_lst = []
# list frames within mxd
for df in arcpy.mapping.ListDataFrames(mxd,"*"):
for bkmk in arcpy.mapping.ListBookmarks(mxd, "", df):
e = bkmk.extent
out_lst.append([bkmk.name.encode("utf-8"), e.XMin,e.YMin,e.XMax,e.YMax,df.rotation,df.scale])
with open(srcPath + "file.txt", "w") as output:
output.write(str(out_lst))