Jason Camerano<\/A> mi dal tento pythonový úryvek:<\/P>head, <\/SPAN>sep<\/SPAN>, <\/SPAN>tail = arcpy.Describe(parcelFabricLayer).Path.partition(".gdb"<\/SPAN>)workspacePath = head + sep<\/SPAN><\/PRE>vysvětlení:<\/P>Describe().Path vrací úplnou cestu, která také obsahuje řetězec ".gdb"<\/P>partition odděluje pomocí poskytnutého ".gdb" <\/SPAN>řetězce na:<\/P>head - před ".gdb" řetězcem<\/SPAN><\/LI>sep - ".gdb" řetězec<\/SPAN><\/LI>tail - za ".gdb" řetězcem<\/SPAN><\/LI><\/UL><\/P>Někdo má lepší metodu?<\/P><\/BODY><\/HTML>
head, <\/SPAN>sep<\/SPAN>, <\/SPAN>tail = arcpy.Describe(parcelFabricLayer).Path.partition(".gdb"<\/SPAN>)workspacePath = head + sep<\/SPAN><\/PRE>vysvětlení:<\/P>Describe().Path vrací úplnou cestu, která také obsahuje řetězec ".gdb"<\/P>partition odděluje pomocí poskytnutého ".gdb" <\/SPAN>řetězce na:<\/P>head - před ".gdb" řetězcem<\/SPAN><\/LI>sep - ".gdb" řetězec<\/SPAN><\/LI>tail - za ".gdb" řetězcem<\/SPAN><\/LI><\/UL><\/P>Někdo má lepší metodu?<\/P><\/BODY><\/HTML>
For Julian's path example I'd normally use os.
a = r"D:\Data\GISData\data\received\Transport.gdb\Routing\AccessRoad" os.path.dirname(os.path.dirname(a)) 'D:\\Data\\GISData\\data\\received\\Transport.gdb'
In Pro you can use the following:
layer.connectionProperties["connection_info"]["database"]
Hi Amir.
I do mine a little different. I don't use arcpy to get my workspace path. I find mine takes a lot quicker as it does not have to call arcpy every time, saving a few seconds. With this method you can also use any geodatabase type (.sde, .gdb or .mdb).
accessRoadFc <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"D:\Data\GISData\data\received\Transport.gdb\Routing\AccessRoad"</SPAN> wkspSplit <SPAN class="operator token">=</SPAN> accessRoadFc<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"."</SPAN><SPAN class="punctuation token">)</SPAN> wkspExt <SPAN class="operator token">=</SPAN> wkspSplit<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\\"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{}.{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>wkspSplit<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> wkspExt<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.