I have a WaterObjects application and would like to export the calculated water quality results to a shapefile of my pipe network. I can do this in WaterCAD by selecting Report->Element Tables -> Pipe, selecting the properties I want to export, and clicking on the export button and selecting ESRI Shapefile as my export format. Would anybody know if this can be accomplished using WaterObjects? I don't necessarily need to see the flex table that gets generated, but if it was necessary to generate the flex table in order to export the shapefile then I could deal with that.
Regards,
Jesse DringoliTechnical Support Manager, OpenFlowsBentley Communities Site AdministratorBentley Systems, Inc.
Answer Verified By: Bruce Jacobs
shapefile.zipJesse,
I seem to be almost there. The shapefile plots fine, however when I open the dbf file all of the fields in every record is Null. I'm in the advanced reply editor and I think I've posted the shapefile as shapefile.zip. I'll put the relevant code here to see if you see something obviously wrong in what I've done.
' Here's where I create the ShapefileDataSourceWriter
Dim dbFields(4) As DBFFieldInfo
dbFields(0) = New DBFFieldInfo("MonYr", DBFFieldType.String)
dbFields(1) = New DBFFieldInfo("Id", DBFFieldType.String)
dbFields(2) = New DBFFieldInfo("conc", DBFFieldType.Double)
dbFields(3) = New DBFFieldInfo("StrtNd", DBFFieldType.String)
dbFields(4) = New DBFFieldInfo("EndNd", DBFFieldType.String)
Dim shpWriter As ShapefileDataSourceWriter = New ShapefileDataSourceWriter()
shpWriter.CreateDataFile(pathShpFle, dbFields, True, ShapeType.Polyline)
' I do a bunch of other stuff here including running WaterCAD
.
' Here's where I save results to the shapefile
For Each aintElementId As Integer In acollection
Dim fldIsActive As IField = junctionElementManager.Element(aintElementId).SupportedFields().Item(nIsActiveFieldIndex) ' 53 = IsActive
If fldIsActive.GetValue(aintElementId) Then
Dim v As Double = CType(f, IResultTimeVariantField).GetValue(aintElementId, id, aiTimeStepCount - 1)
Dim sLabel As String = junctionElementManager.Element(aintElementId).Label
Dim flds4 As Haestad.Support.Support.FieldCollection = junctionElementManager.Element(aintElementId).SupportedFields()
Dim strtNode As String = junctionElementManager.Element(aintElementId).SupportedFields().Item(54).GetValue(aintElementId)
Dim endNode As String = junctionElementManager.Element(aintElementId).SupportedFields().Item(55).GetValue(aintElementId)
Dim strtElem As IModelingElement = junctionElementManager.Element(strtNode)
Dim flds5 As Haestad.Support.Support.FieldCollection = strtElem.SupportedFields()
Dim x0 As Double = 0
Dim y0 As Double = 0
Dim nField As Integer = 0
For Each x As IField In flds5
If (x.Name.Contains("XCoordinate")) Then
x0 = strtElem.SupportedFields().Item(nField).GetValue(strtNode)
y0 = strtElem.SupportedFields().Item(nField + 1).GetValue(strtNode)
Exit For
End If
nField += 1
Next
Dim endElem As IModelingElement = junctionElementManager.Element(endNode)
Dim flds6 As Haestad.Support.Support.FieldCollection = endElem.SupportedFields()
nField = 0
Dim x1 As Double = 0
Dim y1 As Double = 0
For Each x As IField In flds6
x1 = endElem.SupportedFields().Item(nField).GetValue(endNode)
y1 = endElem.SupportedFields().Item(nField + 1).GetValue(endNode)
shpWriter.AddRecordBegin()
shpWriter.WriteFieldData(sMonthYr, "MonYr")
shpWriter.WriteFieldData(sLabel, "Id")
shpWriter.WriteFieldData(v, "conc")
shpWriter.WriteFieldData(strtElem.Label, "StrtNd")
shpWriter.WriteFieldData(endElem.Label, "EndNd")
Dim geoPt0 As GeometryPoint = New GeometryPoint(x0, y0)
Dim geoPt1 As GeometryPoint = New GeometryPoint(x1, y1)
Dim ln() As GeometryPoint = {geoPt0, geoPt1}
shpWriter.WritePolylineGeometry(ln)
shpWriter.AddRecordEnd()