Hello,
We are facing issue for street labeling as we have converted area style shape file to line style shapefile and after converting that to line style if we check that than it just compress the area style polygon box to some level. We have used that shape file for annotation purpose but due to its compress the size of the line intially we have faced issue for some street it did not display labels because of the size of the street line is small than the label text so for that we have set property for TextLineSegmentRatio to 50 so it resolve the issue at some level.
But when we set TextLineSegmentRatio to 50 than it display street lable but its not alligned with the street its display perpendicular rather than aligned with the street.
There are many other street as well where we have same kind of issues.
Please see attached image.
Thanks.
Eric.
Street labeling issue
Some time image or file is not attaching with the post.
Map Suite GIS image
Below is Application image
Hi Eric,
I want to know your detail code about render the lines, I think that’s because some other properties setting.
BTW, have your tried some other properties like: AllowLineCarriage and ForceLineCarriage, which will make label to split parts and maybe it won’t be perpendicular.
Regards,
Don
Hello Don,
First of all I have converted this file from polygon( area) style shape file.
And code for displaying street label is below:
TextStyle customstreename = new TextStyle();
customstreename = TextStyles.CreateSimpleTextStyle("TextString", "Arial", 9, DrawingFontStyles.Bold, new GeoColor(0, 0, 0), 0, 0);
customstreename.DuplicateRule = LabelDuplicateRule.UnlimitedDuplicateLabels;
customstreename.OverlappingRule = LabelOverlappingRule.AllowOverlapping;
customstreename.TextLineSegmentRatio = 80;
customstreename.HaloPen = new GeoPen(new GeoColor(255, 255, 255), 1);
I will check by using property that you have suggested and will post my reply.
Thanks.
Eric.
Hi Eric,
Your code without problem, I put it in our sample DrawCurvedLabels and it works well.
You mentioned you convert polygon to line, I want to make sure that, does that means the lines is two lines but looks one lines now or it still be just a single line? Could you please get the WellKnowText of one your currently line, so I can have a look at it?
Regards,
Don
Hello Don,
I am attaching my code that I have used to convert Area Style shape file to line style shape file. Will you please try to convert one area style to line style and check it at your end and if you required than I will send you my area style shape file using which I have created line style shape file.
Thanks.
Eric.
Don,
There are some issue while attaching file with the post.
so I am pasted my code below
private
void
openFileDialog1_FileOk(
object
sender, CancelEventArgs e)
{
if
(txtNewFileName.Text.Trim() !=
""
)
{
try
{
string
lineShapeFilePath =
string
.Empty;
//RoadAnno100_Line.shp
string
Directorypath = Application.StartupPath +
"\ConvertedFile"
;
if
(!Directory.Exists(Directorypath))
{
Directory.CreateDirectory(Directorypath);
}
lineShapeFilePath = Application.StartupPath +
"\ConvertedFile\" + (txtNewFileName.Text.Contains("
.shp
") == true ? txtNewFileName.Text : txtNewFileName.Text + "
.shp");
ShapeFileFeatureSource areaLayer =
new
ShapeFileFeatureSource(openFileDialog1.FileName);
ShapeFileFeatureLayer.BuildIndexFile(openFileDialog1.FileName, BuildIndexMode.Rebuild);
areaLayer.Open();
Collection<FeatureSourceColumn> featureColumns = areaLayer.GetColumns();
Collection<DbfColumn> columns =
new
Collection<DbfColumn>();
foreach
(var item
in
featureColumns)
{
DbfColumnType type = (DbfColumnType)Enum.Parse(
typeof
(DbfColumnType), item.TypeName);
if
(type == DbfColumnType.Double)
{
columns.Add(
new
DbfColumn(item.ColumnName, type, item.MaxLength, 30));
}
else
{
columns.Add(
new
DbfColumn(item.ColumnName, type, item.MaxLength, 0));
}
}
try
{
ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Polyline, lineShapeFilePath, columns);
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message);
return
;
}
ShapeFileFeatureSource lineLayer =
new
ShapeFileFeatureSource(lineShapeFilePath, ShapeFileReadWriteMode.ReadWrite);
lineLayer.Open();
Collection<Feature> allFeatures = areaLayer.GetAllFeatures(ReturningColumnsType.AllColumns);
foreach
(Feature item
in
allFeatures)
{
lineLayer.BeginTransaction();
Feature lineFeature =
new
Feature(ConvertPolygonsToMultiLine(item.GetShape()
as
AreaBaseShape));
foreach
(KeyValuePair<
string
,
string
> kvp
in
item.ColumnValues)
{
lineFeature.ColumnValues.Add(kvp.Key, kvp.Value);
}
lineLayer.AddFeature(lineFeature);
lineLayer.CommitTransaction();
}
}
catch
(Exception exmain)
{
MessageBox.Show(exmain.Message);
return
;
}
MessageBox.Show(
"Conversion Complete"
+ Environment.NewLine +
"Converted File is at : "
+ Application.StartupPath +
"\ConvertedFile"
);
}
else
{
MessageBox.Show(
"Please enter File Name for Line style file"
);
}
}
private
BaseShape ConvertPolygonsToMultiLine(AreaBaseShape sourceshape)
{
MultilineShape multiLineShapes =
new
MultilineShape();
if
(sourceshape
is
MultipolygonShape)
{
MultipolygonShape multiPolygons = sourceshape
as
MultipolygonShape;
foreach
(var item
in
multiPolygons.Polygons)
{
MultilineShape returnedMultilineShape = ConvertPolygonsToMultiLine(item)
as
MultilineShape;
foreach
(LineShape innerline
in
returnedMultilineShape.Lines)
{
//innerline.ScaleDown(50);
innerline.Simplify(20, SimplificationType.DouglasPeucker);
multiLineShapes.Lines.Add(innerline);
}
}
}
if
(sourceshape
is
PolygonShape)
{
PolygonShape polygon = sourceshape
as
PolygonShape;
if
(polygon.InnerRings.Count > 0)
{
foreach
(RingShape ring
in
polygon.InnerRings)
{
ring.ScaleDown(10);
multiLineShapes.Lines.Add(
new
LineShape(ring.Vertices));
}
}
polygon.OuterRing.ScaleDown(20);
multiLineShapes.Lines.Add(
new
LineShape(polygon.OuterRing.Vertices));
}
return
multiLineShapes;
}
Above is the code that I have used to convert area style shape file to line style shape file. Please check the code and let me know if I made any mistake or need to change in the code.
Thanks.
Eric.
Hi Eric,
We've tried your codes, but it works fine with our test data.
I think the best way is you can send us your area shape files, not all of them but pieces of them would be enough, then we can convert those data to line shape with your code. In that way, I think it is more possible for us to have some further look.
There are some ways to export part of shape file. 1. The recommended way is using map suite GisEditor tool, you can choose the selected features within an area and then export those features to another shape file. 2. export features in programmatic with map suite code. I think you will use some methods like "featuresource.GetFeaturesInsideBoundingBox" to get some "issue" area features and then export them. 3. Some other third-party tools.
Once the data is ready, please refer this link to send us the data wiki.thinkgeo.com/wiki/Map_Suite_Sending_Data_to_Support
Waiting for your feedback.
Thanks,
Troy
Hello Troy,
I will try one of the alternative that you have provided. But for checking area style shape file. I am attaching that shape file with the post.
Please check that by converting from area to line and also check it in GIS editor after converting to line using the code.
Thanks.
Eric.
Hi Eric,
Thanks for the data, it helps us a lot to figure out the issue.
We found the issue is because some multilines, which generated from area shape, includes many vertexes on one side. In map suite, the label will draw on a longest segment from the line and the segment is generated with two vertex. There is a possible that the longest segment is happened on the vertical side of the multi lines.
We took one of the “issue" feature from your data and the vertexes look like as following:
From it we can see the longest segment is on the vertical sides, so the label will draw over there.
Solution:
we can remove the useless vertexes during converting area shape to line shape with the help of Simplify function, try to modify your ConvertPolygonsToMultiLine methods with the below codes:
MultilineShape multiLineShapes = new MultilineShape();
if (sourceshape is MultipolygonShape)
{
MultipolygonShape multiPolygons = sourceshape as MultipolygonShape;
foreach (var item in multiPolygons.Polygons)
{
MultilineShape returnedMultilineShape = ConvertPolygonsToMultiLine(item) as MultilineShape;
MultilineShape simplifiedMultilineShape = returnedMultilineShape.Simplify(GeographyUnit.Meter, 1, DistanceUnit.Meter, SimplificationType.TopologyPreserving);
foreach (LineShape innerline in simplifiedMultilineShape.Lines)
{
innerline.ScaleDown(50);
multiLineShapes.Lines.Add(innerline);
}
}
}
Btw, I am not sure why you did a scaledown for each line, but it will make the shape smaller that the original’s.
Actually, we don’t need to set the Ratio as 80, the ratio means the label length are allowed as 80 times of the longest segment. So it is too large for displaying a label, usually, 1 or 1.5 is enough for most of the case.
Please let us know if any questions.
Thanks,
Troy
Hello Troy,
I have try your code and regenerate line style shape file and check it in my application but it still display misplaced label. Also I have make change in TextLineSegmentRatio but if I make change in that than its not displaying label in street.
I also remove code for ScaleDown to keep shape as in Area shape file.
So can you please provide me shape file that you have created using the code from area shape file that I have provided. Also will you please provide me code that you have used to create line style shape file.
Thanks.
Eric.
Hi Eric,
Would you please try the sample we built for you.
As for the TextLineSegmentRatio, please choose a proper value depends on ratio between text length and the max segment length.
Hope it helps and any question please feel free to let us know.
Thanks
Hello Don,
Thank you for your reply I was working on Geoserver related issue so won’t able to give time for this issue. As I have tried your code but still it display label not at proper place. Can you please check in GIS editor using that converted shape file.
I am also attaching image for more details.
Thanks.
Eric.
Hi Eric,
Sorry that Troy and Don is on vocation now, thus I was
unable to get the test data, but II think the reason is that we always display
the labels on the longest segment of a line shape, but this is reasonable I
guess. Just as Troy mentioned, the first option is that you can do some changes
to your code for converting the area (polygon) shape into line shape, where you
can remove some small segment, but I guess still unable to resolve the problem
that the label displays on a small segment. Another better option is that you
can create a customized TextStyle and overwrite DrawCore method, in the
DrawCore method, we can modify the feature used for drawing label, for example,
we can ignore the feature which is too short, or the angle of the line segment
is not good enough.
Hope it helped.
Thanks,
Johnny