Jason Camerano<\/A> gab mir diesen Python-Schnipsel:<\/P>head, <\/SPAN>sep<\/SPAN>, <\/SPAN>tail = arcpy.Describe(parcelFabricLayer).Path.partition(".gdb"<\/SPAN>)workspacePath = head + sep<\/SPAN><\/PRE>Erklärung:<\/P>Describe().Path gibt den vollständigen Pfad zurück, der auch die Zeichenkette ".gdb" enthält.<\/P>partition trennt diesen anhand der angegebenen ".gdb" <\/SPAN>Zeichenkette in:<\/P>head - vor der ".gdb" Zeichenkette<\/SPAN><\/LI>sep - die ".gdb" Zeichenkette<\/SPAN><\/LI>tail - nach der ".gdb" Zeichenkette<\/SPAN><\/LI><\/UL><\/P>Hat jemand eine bessere Methode?<\/P><\/BODY><\/HTML>
head, <\/SPAN>sep<\/SPAN>, <\/SPAN>tail = arcpy.Describe(parcelFabricLayer).Path.partition(".gdb"<\/SPAN>)workspacePath = head + sep<\/SPAN><\/PRE>Erklärung:<\/P>Describe().Path gibt den vollständigen Pfad zurück, der auch die Zeichenkette ".gdb" enthält.<\/P>partition trennt diesen anhand der angegebenen ".gdb" <\/SPAN>Zeichenkette in:<\/P>head - vor der ".gdb" Zeichenkette<\/SPAN><\/LI>sep - die ".gdb" Zeichenkette<\/SPAN><\/LI>tail - nach der ".gdb" Zeichenkette<\/SPAN><\/LI><\/UL><\/P>Hat jemand eine bessere Methode?<\/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>
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.