Jason Camerano<\/A> me deu este trecho de python:<\/P>head, <\/SPAN>sep<\/SPAN>, <\/SPAN>tail = arcpy.Describe(parcelFabricLayer).Path.partition(".gdb"<\/SPAN>)workspacePath = head + sep<\/SPAN><\/PRE>explicação:<\/P>Describe().Path retorna o caminho completo que também contém a string ".gdb"<\/P>partition separa usando a string fornecida ".gdb" <\/SPAN> para:<\/P>head - antes da string ".gdb"<\/SPAN><\/LI>sep - a string ".gdb"<\/SPAN><\/LI>tail - depois da string ".gdb"<\/SPAN><\/LI><\/UL><\/P>Alguém tem um método melhor?<\/P><\/BODY><\/HTML>
head, <\/SPAN>sep<\/SPAN>, <\/SPAN>tail = arcpy.Describe(parcelFabricLayer).Path.partition(".gdb"<\/SPAN>)workspacePath = head + sep<\/SPAN><\/PRE>explicação:<\/P>Describe().Path retorna o caminho completo que também contém a string ".gdb"<\/P>partition separa usando a string fornecida ".gdb" <\/SPAN> para:<\/P>head - antes da string ".gdb"<\/SPAN><\/LI>sep - a string ".gdb"<\/SPAN><\/LI>tail - depois da string ".gdb"<\/SPAN><\/LI><\/UL><\/P>Alguém tem um método melhor?<\/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>
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.