Jason Camerano<\/A> m'a donné ce snippet python :<\/P>head, <\/SPAN>sep<\/SPAN>, <\/SPAN>tail = arcpy.Describe(parcelFabricLayer).Path.partition(".gdb"<\/SPAN>)workspacePath = head + sep<\/SPAN><\/PRE>explication :<\/P>Describe().Path renvoie le chemin complet qui contient également la chaîne ".gdb"<\/P>partition sépare en utilisant la chaîne fournie ".gdb" <\/SPAN> pour :<\/P>head - avant la chaîne ".gdb"<\/SPAN><\/LI>sep - la chaîne ".gdb"<\/SPAN><\/LI>tail - après la chaîne ".gdb"<\/SPAN><\/LI><\/UL><\/P>Quelqu'un a-t-il une meilleure méthode ?<\/P><\/BODY><\/HTML>
head, <\/SPAN>sep<\/SPAN>, <\/SPAN>tail = arcpy.Describe(parcelFabricLayer).Path.partition(".gdb"<\/SPAN>)workspacePath = head + sep<\/SPAN><\/PRE>explication :<\/P>Describe().Path renvoie le chemin complet qui contient également la chaîne ".gdb"<\/P>partition sépare en utilisant la chaîne fournie ".gdb" <\/SPAN> pour :<\/P>head - avant la chaîne ".gdb"<\/SPAN><\/LI>sep - la chaîne ".gdb"<\/SPAN><\/LI>tail - après la chaîne ".gdb"<\/SPAN><\/LI><\/UL><\/P>Quelqu'un a-t-il une meilleure méthode ?<\/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>
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.